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?
Epsilon closure is finding all the states which can be reached from the present state on one or more elsilon transitions.
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.
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 −
@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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With