Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to compute an epsilon closure?

I am working on a program to convert Non-deterministic finite state automata (NFAs) to Deterministic finite state automata (DFAs). To do this, I have to compute the epsilon closure of every state in the NFA that has an epsilon transition. I have already figured out a way to do this, but I always assume that the first thing I think of is usually the least efficient way to do something.

Here is an example of how I would compute a simple epsilon closure:

Input strings for transition function: format is startState, symbol = endState

EPS is an epsilon transition

1, EPS = 2

Results in the new state { 12 }

Now obviously this is a very simple example. I would need to be able to compute any number of epsilon transitions from any number of states. To this end, my solution is a recursive function that computes the epsilon closure on the given state by looking at the state it has an epsilon transition into. If that state has (an) epsilon transition(s) then the function is called recursively within a for loop for as many epsilon transitions as it has. This will get the job done but probably isn't the fastest way. So my question is this: what is the fastest way to compute an epsilon closure in Java?

like image 610
Darkhydro Avatar asked Feb 14 '11 08:02

Darkhydro


People also ask

What is an epsilon closure?

Epsilon closure is finding all the states which can be reached from the present state on one or more elsilon transitions.

What is the Epsilon closure of finite automata?

The ε closure (P) is a set of states which are reachable from state P on ε-transitions. The epsilon closure is as mentioned below − Find ε-closure for the following Non-deterministic finite automata (NFA) with epsilon. self state+ ε-reachable states. q1 is self-state and q2 is a state obtained from q1 with epsilon input.

What is Q1 and Q2 in Epsilon closure?

q1 is self-state and q2 is a state obtained from q1 with epsilon input. Lets us consider an example to understand more clear about epsilon closure −

What is the Epsilon closure in NFA?

@tkr an epsilon closure is not applied to an NFA. It is applied to a state that has 1 or more epsilon transitions to other state(s), and returns a single state. It is used to get rid of epsilon transitions when converting to a DFA, because a DFA can't have epsilon transitions.


1 Answers

Depth first search (or breadth first search - doesn't really matter) over the graph whose edges are your epilson transitions. So in other words, your solution is optimal provided you efficiently track which states you've already added to the closure.

like image 60
Peter Taylor Avatar answered Oct 06 '22 20:10

Peter Taylor