NFA and epsilon-NFA
Nondeterministic finite automata: the transition function that returns a set of states, epsilon moves and epsilon closure, acceptance as the existence of an accepting computation, simulating an NFA by tracking the set of active states, design by guessing, the epsilon-NFA, how NFAs compare in size with DFAs, and what nondeterminism does and does not add.
Why it exists
A DFA must commit at every step. Many languages are easier to describe if the machine may guess: "the third symbol from the end is a " is simple for a machine that guesses that this is the third from the end and then checks that exactly two symbols follow. A nondeterministic finite automaton (NFA) has that freedom. Nondeterminism does not let finite automata recognise more languages (the subset construction turns every NFA into a DFA) but it makes machines smaller and constructions simpler, and the idea returns for pushdown automata, where it does add power.
Prerequisites
You need the DFA (DFA).
Precise definitions
NFA. as for a DFA, except that returns a set of states (possibly empty). A move on consumes no input symbol. If no move exists the machine is an NFA without ; the general machine is sometimes called an -NFA.
Computation. For an input , a computation is a sequence of states in which each step either follows an edge or reads the next input symbol, and all symbols are read. It is accepting if it ends in an accepting state.
Acceptance. accepts if at least one computation on is accepting; it rejects if every computation fails (ends in a non-accepting state or gets stuck). is the set of accepted strings.
Epsilon closure. is the set of states reachable from the states of by following edges only (zero or more of them); it contains itself.
Extended transition function. and . Then iff .
How it works
Nondeterminism is parallel exploration
There is no magic and no probability: think of the NFA as exploring all choices at once, or as a machine that can duplicate itself at every branching, each copy following one choice. Copies die when they have no move. The string is accepted if some copy is in an accepting state when the input ends. Equivalently, one can simulate the NFA by keeping the set of active states: start with , and for each symbol replace the set by . This simulation takes time and memory and is exactly what the animations show.
Example 1: ends with 01
Three states: loops on and (waiting), on it may also guess "this is the second-last symbol" and move to ; moves to the accepting on . On the input the active sets are , , , , : the last set contains the accepting state , so the string is accepted.
NFA for the binary strings that end with 01: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state p. An NFA can be in several states at once; the string is accepted if SOME choice of moves ends in an accepting state, which is the same as asking whether the set of active states contains an accepting state at the end.
Example 2: the third symbol from the end is 1
Four states: loops on everything; on it may move to (guess: this is the third-last symbol); and move on either symbol; is accepting. The machine can only accept if exactly two symbols follow the guessed . A DFA for this language needs states (it must remember the last three symbols); the NFA needs .
NFA for 'the third symbol from the end is 1': start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state p. An NFA can be in several states at once; the string is accepted if SOME choice of moves ends in an accepting state, which is the same as asking whether the set of active states contains an accepting state at the end.
Example 3: union by guessing, contains 00 or 11
The NFA starts in , which loops forever; on it can guess "a starts here" and go to , on to ; then it checks the next symbol and falls into the accepting, looping state . Two simple machines are glued by letting the start state choose between them. On : , , , , , .
NFA for the binary strings that contain 00 or 11: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state s. An NFA can be in several states at once; the string is accepted if SOME choice of moves ends in an accepting state, which is the same as asking whether the set of active states contains an accepting state at the end.
Epsilon moves
An edge lets the machine change state without reading anything. It is most useful for gluing: to accept make a new start state with edges to the starts of the two machines; for add edges from the accepting states of the first to the start of the second; for add edges back to the start. Following edges repeatedly gives the closure: in the machine below the closure of is , of it is and of it is . The machine recognises ; on the sets are first the closure of , then the -move and its closure, and so on.
epsilon-NFA for (a | b) c*: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state and everything reachable from it by epsilon moves: {i, a1, b1}. An NFA can be in several states at once; the string is accepted if SOME choice of moves ends in an accepting state, which is the same as asking whether the set of active states contains an accepting state at the end.
The smaller machine for shows a single edge from the loop on to the loop on :
epsilon-NFA for a*b*: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state and everything reachable from it by epsilon moves: {s0, s1}. An NFA can be in several states at once; the string is accepted if SOME choice of moves ends in an accepting state, which is the same as asking whether the set of active states contains an accepting state at the end.
What nondeterminism does and does not change
- Same languages. Every NFA (with or without ) has an equivalent DFA, so the languages accepted are exactly the regular languages. Nondeterminism saves states: the -th symbol from the end is needs NFA states and DFA states.
- Removing moves without adding states: let and make a state accepting if its closure contains an accepting state. The result accepts the same language (checked on random machines).
- One accepting state can be arranged for an -NFA (add a new accepting state with edges from the old ones) but not always for an NFA without (the language needs two).
- Complement is not easy: swapping accepting and non-accepting states of an NFA does not give the complement, because a string is accepted if some computation accepts, so after the swap it is accepted if some computation rejects. Determinise first.
- Reversal is easy: reverse every edge, swap start and accepting states (adding edges if there are several accepting states).
- Testing acceptance of a given string is cheap (the set simulation above), but the number of computations can be exponential.
Worked examples
EX 1Simulate by sets
EasyNFA of example 1, input . Start . Read : . Read : from : ; from : ; so . Read : from : ; has no -edge: . Read : . The final set contains : accepted (and indeed ends with ).
EX 2Epsilon closure
EasyStates with edges , , and nothing else on . ; ; . The closure follows paths of any length, but not backwards.
EX 3Design an NFA by guessing
MediumBinary strings whose fifth symbol from the end is . States . loops on and on ; on it may guess "this is the fifth from the end" and move to ; then on any symbol (four more symbols), and accepts: states. The DFA for the same language needs states (it must remember the last five symbols). Guessing the position replaces remembering.
EX 4When is an NFA's answer 'no'?
MediumThe NFA of example 3 on : sets , , , , : the accepting state is never reached; every computation fails: rejected. contains neither nor . The answer "no" needs all computations to fail, while "yes" needs just one: that asymmetry is why complementing an NFA is hard.
EX 5Typical statements
GATE level(a) Every NFA has an equivalent DFA: true. (b) An NFA can accept a language that no DFA accepts: false. (c) The number of states of the smallest DFA is at most for an -state NFA: true, and the bound can be reached. (d) Replacing accepting states by non-accepting ones and vice versa gives an NFA for the complement: false. (e) The language accepted by an -NFA changes if all edges are removed: yes in general: the closures must be taken into account (see the elimination above). (f) An NFA with states accepting a non-empty language accepts a string of length less than : true (a shortest accepted string visits no state twice along an accepting computation).
Cheat box
Cheat box
- NFA: . Accept iff some computation ends in with the whole input read; reject iff all fail.
- Simulation: track the set of active states; . Accept iff the final set meets .
- : states reachable by edges (including the start). edges glue union, concatenation and star.
- Same power as DFAs (regular languages); NFA can be exponentially smaller ( against ).
- Complement of an NFA: determinise first. -removal keeps the number of states.
- Nondeterminism adds no power for finite automata (but does for pushdown automata).
Traps and GATE patterns
Connections
Builds on
Across subjects
No cross-subject links yet.
The NFA is the intermediate form in converting regular expressions to automata; it is turned into a DFA by the subset construction. The same "accept if some computation accepts" idea defines the pushdown automaton, where nondeterminism really adds power.
PYQs
10 previous year questions from your book. I re-solved each one myself (9 by running or simulating, 1 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following two finite automata D1 and D2 (as shown in the figure). Which of the following statements is/are true?
- (a). L(D1)=L(D2)
- (b). L(D1) is a proper subset of L(D2)
- (c). L(D1)∩L(D2)={ε}
- (d). (L(D1)∪L(D2))* consists of all strings in {0,1}* whose length is divisible by 3
Let M be the 5-state NFA with ε-transitions shown in the diagram below Which one of the following regular expressions represents the language accepted by M ?
- (a). (00)* + 1(11)*
- (b). 0* + (1 + 0(00)* )(11)*
- (c). (00)* + (1 + (00)* )(11)*
- (d). 0+ + 1(11)* + 0(11)*
Let
δ
denote
the
transition
function
and
δ̂ denote the extended transition function of the
ε-NFA whose transition table is given below:
δ
ε
a
b
→ q0 {q2} {q1} {q0}
q1
{q2} {q2} {q3}
q2
{q0} ∅
∅
q3
∅
∅
{q2}
Then δ̂ (q2 , aba) is:- (a)∅
- (b){q0,q1,q3}
- (c){q0,q1,q2}
- (d){q0,q2,q3}
Consider the following two statements: I. If all states of an NFA are accepting states then the language accepted by the NFA is Σ*. II. There exists a regular language A such that for all languages B, A ∩B is regular. Which one of the following is CORRECT?
- (a)Only I is true
- (b)Only II is true
- (c)Both I and II are true
- (d)Both I and II are false
Consider the finite automaton in the following figure. What is the set of reachable states for the input string 0011?
- (a){q0,q1,q2}
- (b){q0,q1}
- (c){q0,q1,q2, q3}
- (d){ q3}
What is the complement of the language accepted by the
NFA shown below?
Assume Σ = {a} and ε is the empty string.- (a)∅
- (b){ε}
- (c)a*
- (d){a ,ε}
Let w be any string of length n is {0, 1}*. Let L be the set
of all substrings of w. What is the minimum number of
states in a non-deterministic finite automaton that accepts
L?- (a)n-1
- (b)n
- (c)n+1
- (d)2n-1
Consider the following two finite automata. M1 accepts L1 and M2 accepts L2 Which one of the following is TRUE?
- (a). L1 = L2
- (b). L1 ⊂ L2
- (c). L1 ∩ L2c = ∅
- (d). L1 ∪ L2 ≠ L1
Consider the regular expression R = (a + b)*(aa + bb)(a + b)* Which of the following non-deterministic finite automata recognizes the language defined by the regular expression R? Edges labelled λ denote transitions on the empty string.
- (a).
- (b)
- (c).
- (d).
Consider the non-deterministic finite automaton (NFA) shown in the figure. State X is the starting state of the automaton. Let the language accepted by the NFA with Y as the only accepting state be L1. Similarly, let the language accepted by the NFA with Z as the only accepting state be L2. Which of the following statements about L1 and L2 is TRUE?
- (a)L1 = L2
- (b)L1 ⊂ L2
- (c)L2 ⊂ L1
- (d)None of the above
Self-check
Question 1
An NFA has , , accepting. Is accepted?
Show answerHide
Yes: after the active set is ; reading moves to (and dies): , accepting. Check: the computation exists.
Question 2
What is if has no edges?
Show answerHide
.
Question 3
Why is complementing an NFA by swapping accepting states wrong?
Show answerHide
A string is accepted if some computation accepts; after swapping it is accepted if some computation rejects, which is not the same as all computations rejecting.
Question 4
How many DFA states may be needed for an NFA with states?
Show answerHide
Up to .
Revision card
One-screen revision
- gives a set; moves read nothing; accept iff some computation accepts.
- Simulate with the set of active states and .
- Same languages as DFAs, up to times fewer states; edges glue machines.
- Do not complement by flipping; determinise first.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 1.2 Nondeterminism
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Sections 2.3 and 2.5 (nondeterministic finite automata, epsilon transitions)
- ·Kozen, Automata and Computability, Lecture 5 Nondeterministic finite automata
Verification
On 400 random NFAs (half with epsilon moves) acceptance computed by tracking sets of states was compared with acceptance by trying every computation path, on every string up to length 6: they agree. Epsilon removal (delta'(q, a) = closure(move(closure(q), a))) preserved the language on every string up to length 7. The named NFAs (ends with 01, third symbol from the end, contains 00 or 11, a*b*, (a|b)c*) were compared with independent predicates on every string up to length 10, and the epsilon closures quoted on this page were recomputed. The animations replay the run of the machine by an independent simulation. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)