Finite Automata (DFA and NFA)

Context: FIT2014_MOC · machines that recognise regular languages · the operational counterpart to Regular Expressions (equivalent by Kleene’s Theorem) · Assignment 1 material

Quick Revision

  • 🎯 Objective: read a word letter by letter, moving between finitely many states ➔ accept if you finish in a Final state. The set of accepted strings is the language recognised.
  • 📦 Core Components: DFA ➔ exactly one transition per (state, letter) | NFAzero, one or many, plus -moves.
  • ⚡ Key Constraint: a DFA gives every string a unique path (so complementing = swap Final/non-Final); an NFA accepts if at least one path reaches a Final state — so swapping states does not complement an NFA.

📝 Definition

A finite automaton consists of:

  • A finite set of states ➔ one designated Start State, and some (possibly none) designated Final States.

  • An alphabet of possible input letters.

  • A finite set of transitions ➔ for each state and letter, which state to go to next.

  • Uses ➔ deciding whether a word belongs to a regular language; defining a regular language; lexical analysers.

  • Notation ➔ states are vertices (Start marked by an incoming arrow, Final drawn as a double circle, sometimes written and ); transitions are directed edges labelled by letters.

Two representations

Both describe the same machine — the transition table is the exam-safe form.

stateDiagram-v2
    direction LR
    [*] --> S1
    S1 --> S1: a
    S1 --> S2: b
    S2 --> S3: a,b
    S3 --> S3: a
    S3 --> S2: b
State
Start 112
233
Final 332

⚙️ Execution and acceptance

  • Procedure ➔ begin at the Start State; while input letters remain, read the next letter and move along the edge with that label; at the end, accept if in a Final State, otherwise reject.
  • Accepted / rejected ➔ a string is accepted if its path ends on a Final State.
  • Language recognised ➔ the set of all strings the automaton accepts; we say the FA recognises (or accepts) that language.

Special cases worth being able to build

  • All words accepted · no words accepted · only accepted · only non-empty words accepted · exactly one word accepted.

🔀 The two variants

DFA (deterministic — the plain “FA”)

  • Totality ➔ there is a unique transition from every state for every letter — nothing is missing, nothing is ambiguous.
  • Consequence ➔ every string traces exactly one path, so is a single well-defined state, with Start State.
  • Cost ➔ often needs a sink state (a dead trap absorbing all failures) to keep the table total.

NFA (nondeterministic)

  • Relaxed transitions ➔ for a given state and letter there may be no transition, one, or more than one; labels may also be (change state without reading a letter).
  • Paths ➔ for a given string the path might not exist and might not be unique; if no transition exists for the current letter, the machine crashes.
  • Acceptance ruleaccept if there is at least one path from Start to a Final State; reject only if there are no such paths.
  • Why bother ➔ NFAs are dramatically easier to design: recognising needs a sink state as a DFA, but as an NFA it is a plain 4-state chain.

⚖️ Core Decision Matrix

PropertyDFANFA
transitions per (state, letter)exactly onezero, one, or many
-transitions
path for a given stringuniquenone / one / several
acceptanceunique path ends Finalsome path ends Final
easy to design✗ (sink states)
easy to complement✓ (swap Final/non-Final)
expressive poweridentical — both recognise exactly the regular languages (Kleene’s Theorem)

When It Flips: NFAs are never more powerful, only more convenient — the subset construction converts any NFA into a DFA, at a cost of up to states.

🔄 Complement languages

  • Definition (also written or ).
  • Examples · · .
  • EVEN-EVENstrings with an odd number of s or an odd number of s — note by De Morgan (Boolean Algebra Laws).
  • Construction ➔ given a DFA for , make every Final state non-Final and every non-Final state Final; the result recognises .

📊 Exam Execution Trace

Tracing on the table above (Start , Final ):

StepLetter readState beforeState afterNote
0 (Init)1Start
111self-loop
212
323
433ends in Final ⟹ accepted

⚠️ Common Mistakes

  • 💡 Complement by swapping works only for a total DFA ➔ it relies on every string having exactly one path. On an NFA it fails: a string can have both an accepting and a non-accepting path, so swapping would keep accepting it.
  • 💡 A missing transition is not the same as rejection in a DFA ➔ a DFA’s table must be complete; add an explicit sink state rather than leaving cells blank.
  • 💡 NFA acceptance is existential, not universal ➔ one accepting path is enough, even if a hundred other paths crash.
  • 💡 can be a legitimate state ➔ in the subset construction the empty set of NFA states appears as a genuine (dead) DFA state.

🧠 Active Recall