Chapter 3

Finite automata and state counts

A DFA stores exactly the information about a prefix needed to judge future suffixes. An NFA stores possible computations; a subset construction packages those possibilities into one DFA state.

3.1 DFA and NFA execution

Past papers · CS 2014–2026 (23 papers): 4 questions, 7 marks

A DFA is M=(Q,Σ,δ,q0,F)M=(Q,\Sigma,\delta,q_0,F): finite states QQ, alphabet Σ\Sigma, total transition function δ:Q×Σ→Q\delta:Q\times\Sigma\to Q, start state q0q_0 and final states F⊆QF\subseteq Q. A missing transition in a partial diagram goes to a rejecting sink when completing the DFA. Acceptance requires consuming the whole input and ending in FF.

3.2 Subsets and product constructions

Past papers · CS 2014–2026 (23 papers): 4 questions, 5 marks

Determinise by starting at E({q0})E(\{q_0\}) and creating only reachable subsets. A subset is final exactly when it intersects the old final set. The empty subset is a rejecting sink if reached.

Complement a complete DFA by replacing FF by Q∖FQ\setminus F. Complementing an NFA by swapping final states is generally invalid. Reverse all edges and exchange start/final roles using a fresh ϵ\epsilon-start if necessary to construct an NFA for reversal.

3.3 Distinguishability and minimisation

Past papers · CS 2014–2026 (23 papers): 3 questions, 4 marks

States p,qp,q are distinguishable if some suffix is accepted from exactly one of them. Remove unreachable states, split final from nonfinal states, then repeatedly split blocks according to transition destinations until stable. Each surviving block is one state of the minimal complete DFA.

A minimal complete DFA is unique up to state renaming. Its complement has the same number of states, because swapping acceptance preserves every distinguishing suffix. Empty and universal languages each need one complete DFA state.

For table filling, mark final/nonfinal pairs first. Repeatedly mark a pair if some symbol sends it to an already marked pair. Unmarked pairs are equivalent. For two complete DFAs, reach a final/nonfinal mismatch in their product to disprove equivalence; if none is reachable, they are equivalent.

3.4 Pattern memory and modular arithmetic

Past papers · CS 2014–2026 (23 papers): 10 questions, 17 marks

For a fixed pattern vv of length rr, track the longest suffix of the prefix read so far that is also a prefix of vv. On a new symbol, append it and keep the longest such suffix. For “ends with vv”, continue updating after a match. For “contains vv”, make the matched state absorbing. Avoiding vv uses the complement. Both containing and ending with a fixed nonempty pattern have minimal complete DFAs with r+1r+1 states.

Required memoryConstruction and state-count caution
Several modular countsTuple of residues; product of moduli is an upper bound
Several restrictions on the same countA single residue modulo their least common multiple often suffices
kkth symbol from the right is 11, binary alphabet, k≥1k\ge1NFA guesses it: k+1k+1 states; minimal complete DFA: 2k2^k states
A fixed position from the left and minimum lengthCount until the position; reject a wrong symbol; count the remaining required positions
Length exactly nn or at most nn, n≥0n\ge0n+2n+2 states in a minimum complete DFA, including the rejecting sink
Length at least nn, n≥0n\ge0n+1n+1 states, with the reached threshold absorbing
kkth symbol from the left is a specified symbol, k≥1k\ge1k+2k+2 states for an alphabet with at least two symbols: count, accept and reject
Running product in a finite group GG; every group element allowed as a symbolStore the product; ∣G∣\lvert G\rvert states are necessary for identity acceptance
Permutations of rr objects, all allowed, product must be identityr!r! states; append one inverse to distinguish any two products

For the kkth-from-right language, store a length-kk bit window with leading zero padding before enough symbols arrive. All 2k2^k windows are reachable; shift a differing position to the tested position to distinguish two windows.

A DFA accepting an even number of a symbols; b preserves the state.A DFA accepting an even number of a symbols; b preserves the state.

3.5 Counting accepted words

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks

Count deterministic paths by input length. If using an NFA, determinise first; otherwise several paths for the same word cause overcounting. The transition matrix counts distinct symbols that induce each edge, not merely the existence of an edge.

3.6 Regular-language decision tests

For a finite automaton, emptiness is reachability of a final state. Infiniteness means a reachable directed cycle lies on a path to a final state; remove irrelevant states before testing cycles. In an ϵ\epsilon-NFA that cycle must allow consumption of a nonempty string. Determinisation avoids this qualification.

The shortest accepting path cannot repeat a state. An accepting path of at least nn edges has a productive cycle; a shortest accepted word of length at least nn can be shortened into the stated interval by deleting cycles. The equivalence bound follows from a shortest path to a mismatch in the product.

Universality is emptiness of the complement. Inclusion L1⊆L2L_1\subseteq L_2 is emptiness of L1∖L2L_1\setminus L_2. Equality requires both inclusions, or emptiness of symmetric difference. Membership, emptiness, finiteness, universality, inclusion, equivalence and disjointness are all decidable for regular representations.

Last-minute recall

  • A complete DFA must have a transition for every state and symbol.
  • A final state accepts only when the whole input has been consumed.
  • The subset bound is 2n2^n, not a mandatory state count.
  • Remove unreachable states before minimising.
  • A matching construction proves an upper bound; suffixes prove the lower bound.
  • Complement preserves the minimum complete DFA state count.
  • Count words with a DFA, not nondeterministic paths.
  • Productive cycles distinguish infinite from finite regular languages.

Revise offline: the whole Theory of Computation handbook as one PDF

40 pages · 1.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections