Skip to content
Part IA Michaelmas, Lent Term

NFA: Nondeterministic Finite Automata

Definition

A nondeterministic finite automaton (NFA) is a tuple M=(Q,Σ,Δ,s,F)M = (Q, \Sigma, \Delta, s, F) where:

ComponentDescription
QQFinite set of states
Σ\SigmaInput alphabet (finite)
ΔQ×Σ×Q\Delta \subseteq Q \times \Sigma \times QTransition relation
sQs \in QStart state
FQF \subseteq QSet of accepting states

Key Feature: Nondeterminism

From a state qq on input aa, there may be:

  • Zero transitions: no next state
  • One transition: one next state (like DFA)
  • Multiple transitions: several possible next states

NFA example with transitions

Extended Transition Relation

One-Step Transition

Write qaqq \xrightarrow{a} q' if (q,a,q)Δ(q, a, q') \in \Delta.

Multi-Step Transition

Define qwqq \xrightarrow{w} q' (there is a path from qq to qq' labelled by ww) inductively:

qεqqaqqwqqawq\frac{}{q \xrightarrow{\varepsilon} q} \qquad \frac{q \xrightarrow{a} q'' \quad q'' \xrightarrow{w} q'}{q \xrightarrow{aw} q'}

Language

The NFA accepts string ww if there exists an accepting state reachable from the start:

wL(M)    qfF.swqfw \in L(M) \iff \exists q_f \in F. s \xrightarrow{w} q_f

Example: Contains “ab”

NFA that accepts strings over {a,b}\{a, b\} containing substring “ab”:

NFA for "contains ab"

  • Q={q0,q1,q2}Q = \{q_0, q_1, q_2\}
  • Transitions:
    • q0aq0q_0 \xrightarrow{a} q_0, q0bq0q_0 \xrightarrow{b} q_0 (stay in q0q_0 until we see ‘a’)
    • q0aq1q_0 \xrightarrow{a} q_1 (transition to q1q_1 if we see ‘a’)
    • q1bq2q_1 \xrightarrow{b} q_2 (transition to accepting on ‘b’)
    • q2aq2q_2 \xrightarrow{a} q_2, q2bq2q_2 \xrightarrow{b} q_2 (stay accepting)
  • s=q0s = q_0, F={q2}F = \{q_2\}

Example: Ends with “ab”

NFA that accepts strings ending in “ab”:

NFA for "ends with ab"

  • Q={q0,q1,q2}Q = \{q_0, q_1, q_2\}
  • Transitions:
    • q0aq0q_0 \xrightarrow{a} q_0, q0bq1q_0 \xrightarrow{b} q_1
    • q1aq2q_1 \xrightarrow{a} q_2, q1bq1q_1 \xrightarrow{b} q_1
    • q2aq0q_2 \xrightarrow{a} q_0, q2bq1q_2 \xrightarrow{b} q_1
  • Or: more standard construction with q0a,bq0q_0 \xrightarrow{a,b} q_0, plus q0aq1q_0 \xrightarrow{a} q_1, q1bq2q_1 \xrightarrow{b} q_2
  • s=q0s = q_0, F={q2}F = \{q_2\}

Non-acceptance

An NFA rejects string ww if:

  • No path from ss reaches any accepting state on input ww, OR
  • The computation “gets stuck” (no valid transition)

Note: Nondeterminism means existential acceptance — if ANY path reaches accepting, the string is accepted.

Size and Complexity

  • Number of states: Q|Q|
  • Number of transitions: Δ|\Delta|
  • For each state-symbol pair, potentially Q|Q| outgoing transitions

Summary

  • NFA: (Q,Σ,Δ,s,F)(Q, \Sigma, \Delta, s, F) with nondeterministic transition relation
  • A string is accepted if SOME path reaches an accepting state
  • Multiple transitions from a state on the same symbol allowed
  • No transition on a symbol means that path dies