Open In App

Conversion of Epsilon-NFA to NFA

Last Updated : 10 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

An NFA (Non-deterministic Finite Automaton) is a theoretical model used to recognize patterns and determine whether a string belongs to a specific language. An Epsilon-NFA (ε-NFA) is a special type of NFA where transitions can happen without reading any input symbol, using epsilon (ε) transitions.

  • An NFA allows multiple possible transitions from a given state based on the input symbol.
  • The key difference between them is that Epsilon-NFAs have epsilon transitions, while regular NFAs only transition on specific input symbols.
  • Converting an Epsilon-NFA to an NFA eliminates the epsilon transitions, allowing us to apply standard NFA algorithms for language recognition.
epsilonNFA1
Epsilon (ε) Transition

Epsilon-NFA to NFA Conversion Steps

Step 1: Find the Epsilon Closure

  • For each state in the Epsilon-NFA, find its epsilon closure.
  • This means figuring out all the states that can be reached by only using epsilon transitions (and include the state itself).
  • This helps in tracking which states can be reached without reading any input symbol.

Step 2: Create New States for the NFA

  • Each state in the new NFA corresponds to a set of states you found in the epsilon closures.
  • The starting state in the NFA will be the epsilon closure of the initial state of the Epsilon-NFA.

Step 3: Define the Transitions

  • For each state in the NFA (which represents a group of states from the epsilon closures), look at what happens when you read each input symbol.
  • For an input symbol a, check which states you can reach from any state in the current group, and then find the epsilon closure of those states.
  • This way, you're considering both direct transitions and the ones that happen because of epsilon moves.

Step 4: Set Accepting States

  • Any state in the NFA that includes at least one accepting state from the Epsilon-NFA becomes an accepting state.
  • This ensures that the NFA recognizes all the same strings as the Epsilon-NFA.

Step 5: Keep Going Until Done

  • Keep processing each new state and its transitions until no more new states are created.
  • This guarantees that every possible state is covered, and there are no epsilon transitions left.

Example of Epsilon-NFA to NFA Conversion

Convert the following ε-NFA to NFA. The ε-NFA has states q0, q1, q2, q3, q4 where q0 is the initial state and q2 final state.

Epsilon-NFA
ε-NFA

Solution

In the above example, we have 5 states named as q0, q1, q2, q3 and q4. Initially, we have q0 as start state and q2 as final state. We have q1, q3 and q4 as intermediate states.

According to ε-NFA the states follow following transitions:

  • State q0 when,
    • Input 0: No transition
    • Input 1: Moves to q1
    • Input ε: Moves to q2
  • State q1 when,
    • Input 0: No transition
    • Input 1: Moves to q0
    • Input ε: No transition
  • State q2 when,
    • Input 0: Moves to q3
    • Input 1: Moves to q4
    • Input ε: No transition
  • State q3 when,
    • Input 0: Moves to q2
    • Input 1: No transition
    • Input ε: No transition
  • State q4 when,
    • Input 0: Moves to q2
    • Input 1: No transition
    • Input ε: No transition

Transition table for the state transitions:

States/InputInput 0Input 1Input epsilon
q0-q1q2
q1-q0-
q2q3q4-
q3q2--
q4q2--

We can see that we have an epsilon move from state q0 to state q2, which is to be removed. To remove epsilon move from state q0 to state q1, we will follow the steps mentioned below. 

Step 1: Considering the epsilon move from state q0 to state q2. Consider the state q0 as vertex v1 and state q2 as vertex v2. 

ENFA5

Step 2: Now find all the moves that starts from vertex v2 (i.e. state q2). After finding the moves, duplicate all the moves that start from vertex v2 (i.e state q2) with the same input to start from vertex v1 (i.e. state q0) and remove the epsilon move from vertex v1 (i.e. state q0) to vertex v2 (i.e. state q2). Since state q2 on getting input 0 goes to state q3. Hence on duplicating the move, we will have state q0 on getting input 0 also to go to state q3.

Similarly state q2 on getting input 1 goes to state q4. Hence on duplicating the move, we will have state q0 on getting input 1 also to go to state q4. So, NFA after duplicating the moves is:

223-1
NFA on Duplicating Moves

Step 3: Since vertex v1 (i.e. state q0) is a start state. Hence we will also make vertex v2 (i.e. state q2) as a start state. Note that state q2 will also remain as a final state as we had initially. NFA after making state q2 also as a start state is:

3164-1
NFA after making state q2 as a start state

Step 4: Since vertex v2 (i.e. state q2) is a final state. Hence we will also make vertex v1 (i.e. state q0) as a final state. Note that state q0 will also remain as a start state as we had initially. After making state q0 also as a final state, the resulting NFA is:

4108-1
Resulting NFA (state q0 as a final state)

The transition table for the above resulting NFA is:

States/InputInput 0Input 1
q0q3q1,q4
q1-q0
q2q3q4
q3q2-
q4q2-

Similar Reads