CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 1 · Finite Automata

Lesson 1.2.1 · Item 20 of 91

Nondeterminism and the NFA

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. Product DFA for L₁ ∩ L₂: accepting set?
    Stuck? Peek at 1.1.4 Product construction and complement
    • Product: states Q₁×Q₂, δ((p,q),a) = (δ₁(p,a), δ₂(q,a)), start (s₁,s₂).
    • ∩: F₁×F₂. ∪: F₁×Q₂ ∪ Q₁×F₂. −: F₁×(Q₂−F₂). ≤ |Q₁|·|Q₂| states.
    • Complement: complete the DFA (add dead state), swap F ↔ Q−F; same state count.
    • Regular languages closed under ∪, ∩, −, complement.

    Read lesson 1.1.4

  2. Minimal DFA for strings ending with ab?
    Stuck? Peek at 1.1.3 DFA design patterns
    Language (|w| = k pattern)Minimal states
    starts with wk + 2
    contains w / ends with wk + 1
    |x| ≡ r mod nn
    |x| = k, |x| ≤ kk + 2
    |x| ≥ kk + 1
    #a mod m and/or #b mod nm·n (typical)
    binary value ≡ 0 mod k, k oddk
    binary ÷ 2ʲj + 1
    k-th symbol from start fixedk + 2

    Divisibility update: r ← (base·r + digit) mod k.

    Read lesson 1.1.3

  3. What does |P(Q)| equal when |Q| = n?
    Stuck? Peek at 0.2.1 Sets
    • x ∈ A (element) vs X ⊆ A (subset). ∅ ⊆ every set. A = B ⇔ A ⊆ B and B ⊆ A.
    • A ∪ B, A ∩ B, A − B = A ∩ B̅, A̅ = U − A. De Morgan: (A∪B)̅ = A̅∩B̅, (A∩B)̅ = A̅∪B̅.
    • |A ∪ B| = |A| + |B| − |A ∩ B|. |A × B| = |A|·|B|. |P(A)| = 2^|A|.
    • |∅| = 0, |{∅}| = 1, P(∅) = {∅}.

    Read lesson 0.2.1

The Hook

You’re looking for a friend in a maze of corridors. A DFA must commit to one corridor at every junction. But imagine you could split into copies at every junction, each copy exploring one corridor at once; if any copy finds your friend, you succeed. That’s nondeterminism. No real machine clones itself — but as a design tool it is spectacular: some languages that need huge DFAs have tiny machines of this kind.

Predict First

For “strings over {0,1} whose 3rd symbol from the end is 1”, a guessing machine needs only 4 states (below). How many states do you think the smallest DFA for the same language needs?

Core Concept

Prediction check

Answer: 8 = 2³. The DFA must remember the last 3 symbols — every one of the 8 combinations behaves differently. The guessing machine just “guesses” which 1 is third from the end and verifies that exactly two symbols follow. Chapter 1.2.3 shows where the 2ⁿ comes from.

22k=1342483516463257646
NFA states (k + 1)DFA states (2ᵏ)
“k-th symbol from the end is 1”: guessing keeps the machine tiny; remembering forces 2ᵏ states.

What changes from a DFA

In a Nondeterministic Finite Automaton (NFA), from a state on a symbol there may be zero, one, or several next states. Zero moves = that copy dies quietly. Several = the machine splits.

NFA N = (Q, Σ, δ, q₀, F) with δ : Q × Σ → P(Q). δ(q, a) is a set of states (possibly ∅).
DFA
exactly one move per (state, symbol)
NFA
zero, one or many moves
zero moves
that copy dies quietly
many moves
the machine splits into copies
Nondeterminism in one picture.

How an NFA accepts

N accepts w if at least one path from q₀ spelling w ends in an accepting state. N rejects w if every path either dies or ends in a non-accepting state.

Two equivalent ways to picture it:

  • Guessing: the machine magically guesses the right choice at every split.
  • Parallel copies (set of states): track the set of all states some copy could be in. Start {q₀}; on symbol a, the new set is the union of δ(q, a) over all q in the current set. Accept iff the final set contains an accepting state.
steps illustration
Computation tree of the ends-with-ab NFA on “aab”. One ✓ leaf is enough to accept.

Extended δ̂ for NFAs

δ̂(q, ε) = {q}; δ̂(q, wa) = ⋃ over p ∈ δ̂(q, w) of δ(p, a). L(N) = { w | δ̂(q₀, w) ∩ F ≠ ∅ }.

readactive set
start{q0}
a{q0, q1}
a{q0, q1}
b{q0, q2} ✓
The same run tracked as a set of states — the view that leads to the subset construction.

Every DFA is an NFA

A DFA is just an NFA where every δ(q, a) has exactly one element. So NFAs can do at least what DFAs do. The surprising theorem (Lesson 1.2.3) is the converse: every NFA can be converted to an equivalent DFA. NFAs accept exactly the regular languages — they are convenient, not stronger.

as machines
every DFA is an NFA (one choice each time)
as languages
NFAs accept exactly the regular languages — no more
More freedom, same power.

Why missing moves are fine

An NFA does not need a dead state: a missing move simply kills that copy. So NFA state counts are often smaller, and “minimal NFA” is a different (and much harder) question than “minimal DFA”.

DFA for “ends with ab”
3 states, every arrow present
NFA for “ends with ab”
3 states, missing arrows allowed, no dead state
Missing moves are fine in an NFA.

Putting it together

  • An NFA may have 0, 1 or many moves; it accepts if any path ends in F.
  • Track the set of active states — that is the bridge to DFAs.
  • NFAs are more convenient, not more powerful; swapping F does not complement them.

Visual

NFA: ends with ab

States: q0, q1, q2

Transitions: q0>q0: a,b; q0>q1: a; q1>q2: b

set-of-states trace for "aab" on the ends-with-ab NFA
start      {q0}
read a  →  {q0, q1}        (q0 stays, q0 also guesses "this a starts the final ab")
read a  →  {q0, q1}        (q1 has no move on a: that copy dies; q0 splits again)
read b  →  {q0, q2}        (q0 stays; q1 ─b→ q2)
end: q2 ∈ F → ACCEPT

"aba": {q0} ─a→ {q0,q1} ─b→ {q0,q2} ─a→ {q0,q1}   no final state → REJECT
NFA: 3rd symbol from the end is 1

States: q0, q1, q2, q3

Transitions: q0>q0: 0,1; q0>q1: 1; q1>q2: 0,1; q2>q3: 0,1

Worked Examples

Easy

In the ends-with-ab NFA, what is δ(q0, a)? δ(q1, a)?

Show the full solution

δ(q0, a) = {q0, q1} (two choices). δ(q1, a) = ∅ (no move — that copy dies).

Medium

Trace “1101” on the 3rd-from-end NFA with sets of states.

Show the full solution

{q0} ─1→ {q0,q1} ─1→ {q0,q1,q2} ─0→ {q0,q2,q3} ─1→ {q0,q1,q3}. Contains q3 ⇒ accept (third from the end of 1101 is 1 ✓). For “1010”: {q0} ─1→ {q0,q1} ─0→ {q0,q2} ─1→ {q0,q1,q3} ─0→ {q0,q2} ⇒ reject ✓.

GATE-level

Design an NFA for strings over {a,b} that contain abb or end with ba. How many states?

Show the full solution

Take a start state s with a self-loop on a,b. Branch 1: s ─a→ 1 ─b→ 2 ─b→ 3 (accepting, self-loop a,b). Branch 2: s ─b→ 4 ─a→ 5 (accepting, no outgoing moves). Total 6 states, built by just placing the two patterns side by side — the guessing does the work. A DFA would need careful merging of both patterns.

GATE Traps

  • NFA acceptance needs only ONE accepting path; rejection needs ALL paths to fail.
  • Swapping F in an NFA does not complement its language (a string can have both an accepting and a non-accepting path).
  • δ(q, a) = ∅ is allowed in an NFA — no dead state needed.
  • NFAs are not more powerful than DFAs; they accept exactly the regular languages.

Memory Hook

An NFA is a search party: it fans out at every fork, and one shout of “found it!” from any member wins.

Connect the Dots

An NFA reads one symbol per move. What if a machine could also jump between states without reading anything? That small extra freedom makes gluing machines together trivial — next lesson.

Self-Test

  1. MCQ

    For an NFA, δ maps Q × Σ to:

    1. Q
    2. P(Q)
    3. Σ
    4. Q × Q
  2. MSQ

    Which are true?

    1. Every DFA is an NFA
    2. Some NFA accepts a non-regular language
    3. NFA accepts w if some path ends in F
    4. An NFA must have a dead state
  3. NAT

    The 3rd-from-end NFA: how many states are in the active set after reading “111”?

    Write your answer before opening the key.

  4. MCQ

    The ends-with-ab NFA with F swapped (F = {q0, q1}) accepts:

    1. strings not ending in ab
    2. Σ* (every string, including ab)
    3. only ε
    4. ∅

Rule Card

  • NFA: δ : Q × Σ → P(Q); moves may be 0, 1, many.
  • Accept iff some path ends in F ⇔ δ̂(q₀, w) ∩ F ≠ ∅. Track the set of active states.
  • DFA ⊆ NFA; NFAs accept exactly the regular languages.
  • No dead state needed. Swapping F does NOT complement an NFA.

Concept Ledger

  • nondeterminism
  • NFA, δ : Q × Σ → P(Q)
  • computation path / branch
  • NFA acceptance (some path)
  • active set of states
  • δ̂ for NFAs

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. F₁ × F₂.
  2. 3 states.
  3. 2ⁿ.

Self-test answers

  1. B — A set of possible next states.
    • A: That is a DFA.
    • C: Wrong codomain.
    • D: Not a set of states.
  2. AC — NFAs accept exactly the regular languages.
    • B: NFAs = DFAs in power.
    • D: Missing moves are allowed.
  3. 4 — {q0,q1,q2,q3}.
  4. B — q0 has a self-loop on a and b, so q0 is active after every string, and q0 is now accepting. Swapping F does not complement an NFA.
    • A: That would be the true complement; swapping does not produce it.
    • C: Every string keeps q0 active.
    • D: q0 is always active and accepting.

Flashcards

  1. When does an NFA accept w?
    Reveal answerWhen at least one path spelling w ends in an accepting state.
  2. Are NFAs more powerful than DFAs?
    Reveal answerNo — they accept exactly the regular languages.
  3. Does swapping F complement an NFA?
    Reveal answerNo.
  4. States of a smallest NFA for “k-th symbol from the end is 1”?
    Reveal answerk + 1.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.