Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 15

NFA-ε: Definition and Conversion to NFA

Recommended resources

Hello! Welcome back to our journey into the Theory of Computation.

In the last lesson, we focused on constructing regular expressions to describe languages with specific patterns. We saw how to translate constraints like "starts with," "contains," or "number of symbols is a multiple of k" into the formal syntax of regular expressions.

Today, we take the first step in connecting the world of descriptive regular expressions back to the machine-based world of automata. Our goal is to define a new type of automaton, the NFA with ε-transitions (NFA-ε), and show how to convert it into an equivalent standard NFA. This new model is a crucial stepping stone that will allow us to eventually prove that regular expressions and finite automata are equally powerful.

Why Add ε-Transitions?

So far, our automata could only change state after reading an input symbol. An NFA-ε introduces a new capability: the ability to change state without consuming any input. This is represented by an ε-transition, sometimes called a "null" or "empty" transition.

Why is this useful? Think about the regular expression a*. It represents zero or more a's. An ε-transition provides a natural way to model the "zero" case or the optionality inherent in the Kleene star and union operators. These "free moves" make it much easier to build automata directly from regular expressions, as we'll see in our next lesson.


Formal Definition of an NFA-ε

An NFA-ε is very similar to a standard NFA, with one key change to the transition function.

Epsilon NFA

Let's start with a formal introduction to what an NFA-ε is and how it differs from a standard NFA. This video from Neso Academy provides a clear definition and a simple visual example.

Watch from 00:34 to 04:18. Focus on: The meaning of the ε symbol as an empty or null input. The formal 5-tuple definition, specifically how the transition function δ changes to include ε. It becomes δ: Q × (Σ ∪ {ε}) → 2^Q. How an ε-transition appears in a state diagram and what it means for a machine to change state 'on seeing nothing'.

As the video explains, an NFA-ε is a 5-tuple , where:

  • is the finite set of states.
  • is the input alphabet.
  • is the transition function, . This is the crucial difference: the function now accepts the empty string as a possible input.
  • is the start state.
  • is the set of final states.

The power of an NFA-ε comes from its ability to be in multiple states at once, not just through nondeterministic choices on an input symbol, but also by following these "free" ε-paths simultaneously.


The ε-Closure: Tracking All Possible "Free" Moves

To work with an NFA-ε, we need a way to track all the states the machine could possibly be in at any given moment, including all the states reachable through ε-jumps. This is the job of the ε-closure.

The ε-closure of a state , written as ε-closure(q) or E(q), is the set of all states reachable from by following zero or more ε-transitions.

  • Zero ε-moves: A state is always in its own ε-closure.
  • One or more ε-moves: We follow all possible paths of ε-transitions from and add every state we visit to the set.
NFA-ε and Epsilon Closure Definition with Example
In this diagram, the ε-closure of state A, E(A), is {A, B, C}. This is because you can stay at A (zero moves), or jump from A to B, and from B to C, using only ε-moves. Similarly, E(B) = {B, C}, and E(C) = {C}.

The following video provides a more formal definition and a clear, animated example of how to compute the ε-closure.

ε-closure: what is it? (epsilon closure)

The ε-closure is the most important concept for understanding and converting NFA-ε. This video from Easy Theory provides an excellent formal and intuitive explanation.

Watch from 04:17 to 08:50, and then the clarification from 10:07 to 11:20. Pay close attention to: The formal definition of ε-closure as the smallest set of states satisfying certain rules. The step-by-step process of finding the ε-closure by iteratively adding states reachable via outgoing ε-transitions. The important point that we only follow outgoing ε-transitions from the current set, not incoming ones.

Test your understanding!

Consider the NFA-ε from the first video (Neso Academy, resource LINK, at timestamp 02:45). What are the ε-closures for states A, B, C, and D?
(Remember the video's rule: every state is assumed to have an ε-transition to itself, even if not drawn).

Show answer
  • ε-closure(A): {A}. There are no outgoing ε-transitions from A (other than to itself).
  • ε-closure(B): {B, C}. From B, you can stay at B or take the ε-transition to C.
  • ε-closure(C): {C}. No outgoing ε-transitions from C.
  • ε-closure(D): {D}. No outgoing ε-transitions from D.

Converting an NFA-ε to an Equivalent NFA

Our next step is to prove that ε-transitions, while convenient, do not add any fundamental power to our machines. We do this by showing that for any NFA-ε , we can construct a standard NFA that accepts the same language.

The Core Idea: A single transition in our new NFA on an input symbol a will simulate a three-step process in the original NFA-ε :

  1. First, make any possible ε-moves.
  2. Then, consume the single input symbol a.
  3. Finally, make any subsequent ε-moves.

This logic is captured formally in the definition of the new transition function, .

How to convert NFA with epsilon to without epsilon?

Let's now formalize the conversion algorithm. We will define a new transition function, δ', for our target NFA (without ε) that simulates the behavior of the original NFA-ε. This article provides a clear, formula-based method.

Read the first part of the article, up to the 'Example' section. The key takeaway is the formula for the new transition function δ', which elegantly captures the three-step simulation process: δ'(q, a) = ε-closure(δ(ε-closure(q), a))

Let's break down that crucial formula:

  1. ε-closure(q): This is Step 1. Start at state and find all states reachable via free ε-moves. Let's call this set of states .
  2. δ(S, a): This is Step 2. From all the states in , find where you can go by consuming the single input symbol . Let this new set of states be .
  3. ε-closure(T): This is Step 3. From all the states in , find all the states you can now reach via another set of free ε-moves. This final set is the result for .

The construction of the equivalent NFA is as follows:

  • States: The states are the same, .
  • Alphabet: The alphabet is the same, .
  • Start State: The start state is the same, .
  • Transition Function: is computed using the formula above for every state and every symbol in .
  • Final States (): This is the last piece. A state in is a final state if its ε-closure in (the original machine) contains at least one of the original final states from . Formally, .

The image below gives a complete visual walkthrough of this process, from the original NFA-ε to the final NFA transition table.

Epsilon NFA to NFA Conversion Example
This image provides a complete example. On the left is the NFA-ε. First, the ε-closure for each state is computed. Then, the formula δ'(q, a) = E*(δ(E*(q), a)) is used to calculate the new transitions for the NFA without ε. For instance, to find the new transition from state A on input 0, we compute E*(δ(E*(A), 0)). Since E*(A) = {A,B,C}, we find where those states go on 0, which is {A,B}. Then we take the ε-closure of {A,B}, which is E*(A) ∪ E*(B) = {A,B,C}. So, δ'(A,0) = {A,B,C}.

An Alternative View: Edge Duplication

For those who prefer a more graphical approach, you can also think of the conversion as "bypassing" the ε-transitions. If you have a path p --ε--> q --a--> r, the algorithm effectively creates a new direct path p --a--> r. The following resource explains this more visual method. While the formal formula is more robust for complex cases, this method can be very helpful for building intuition.

Epsilon NFA To NFA Conversion Algorithm

There is also a more visual, 'edge-duplication' method for this conversion. This article walks through the algorithm and provides a simple example.

Read the sections 'Epsilon NFA To NFA Conversion Algorithm' and 'Example 01'. This will show you how to remove an ε-edge from state V1 to V2 by duplicating all of V2's outgoing edges at V1 and adjusting the final/initial state properties.


Conclusion

In this lesson, we introduced a powerful new tool, the NFA-ε, and demonstrated that it is equivalent in power to a standard NFA. This is a significant result, as it provides a necessary link in the chain connecting different formalisms for regular languages.

Key Takeaways:

  • An NFA with ε-transitions (NFA-ε) can change states without consuming an input symbol. Its transition function is defined on .
  • The ε-closure of a state is the set of all states reachable from it using only ε-moves (including the state itself).
  • Any NFA-ε can be converted to an equivalent NFA using the formal conversion algorithm based on the formula: .
  • This equivalence means that ε-transitions are a convenient tool for design but do not extend the class of languages that can be recognized.

Preview of the Next Lesson:
We've now built the first part of our bridge from regular expressions to finite automata. We have a machine model, the NFA-ε, that is perfectly suited for this task. In our next lesson, we will learn Thompson's construction algorithm, a beautiful and systematic method to convert any given regular expression into an equivalent NFA-ε. This will bring us one giant step closer to proving Kleene's Theorem—the grand unification of regular expressions and finite automata.