Regular Expressions, Finite Automata and Regular Languages
NFAs: Same Power, Exponentially Less Room
Subset construction turns any n-state NFA into a DFA of at most 2ⁿ states, so the two models recognise exactly the same languages — nondeterminism buys no power at all. What it buys is size. The language "the third symbol from the end is a" has an obvious 4-state NFA: guess that the current symbol is the one, then count two more. Its minimal DFA needs 8 states, because a deterministic machine cannot guess and must instead remember the last three symbols. Both figures here were computed, and the gap widens as 2^k for "the k-th from the end".
| Operation | Regular languages | How you know |
|---|---|---|
| Union, concatenation, Kleene star | Closed | Regular expressions are built from them |
| Complement | Closed | Swap accepting and non-accepting states of a DFA |
| Intersection | Closed | Product construction, or De Morgan from the two above |
| Reversal, homomorphism | Closed | Reverse the NFA; relabel the transitions |
Key takeaways
- A DFA state is a memory of exactly what still matters — count the distinguishable situations.
- Independent conditions multiply: a mod 2 and b mod 3 gives 6 states, not 5.
- Caring about the k-th symbol from the end costs 2^k states — 8 for the third.
- Myhill–Nerode: minimal DFA states = equivalence classes, so the minimal DFA is unique up to renaming.
- Infinitely many pairwise-distinguishable strings prove non-regularity in one line.
- NFAs recognise exactly the regular languages but can be exponentially smaller — 4 states against 8.
- Regular languages are closed under union, concatenation, star, complement, intersection and reversal.
- Swapping accepting states complements a DFA and NOT an NFA, because an NFA accepts if ANY path does.
Practice questions (8)
Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.
Over the alphabet {a, b}, how many states does the minimal DFA accepting all strings whose third symbol from the end is a have?
Numerical answer — type the value.
Show answer
Answer: 8
A deterministic machine cannot know which symbol will turn out to be third from the end, so it must remember the last three symbols at all times: 2³ = 8 states, and minimisation confirms none of them merge. The same language has a 4-state NFA — guess that the current symbol is the one and count two more — which is the standard demonstration that nondeterminism buys size rather than power. The general figure is 2^k for the k-th symbol from the end, so the same question about the fifth would answer 32.How many states does the minimal DFA accepting binary strings that represent numbers divisible by 5, read most significant bit first, have?
Numerical answer — type the value.
Show answer
Answer: 5
Five. The only thing worth remembering is the value read so far modulo 5, since reading another bit takes the running value v to 2v or 2v + 1, and that update depends on v only through its remainder. So the states are the residues 0 to 4, the start and only accepting state is 0, and minimisation shows no two residues merge. The pattern generalises immediately: divisibility by k needs exactly k states, whatever k is, which makes this a question you can answer without drawing anything.Over {a, b}, the minimal DFA for strings with an even number of a and a number of b divisible by 3 has:
Show answer
Answer: B — 6 states
The two conditions are independent — the a-count says nothing about the b-count — so the machine must track both and the state count is the product: 2 × 3 = 6, confirmed by minimisation. Option A adds the moduli instead of multiplying, which is the commonest error. The rule is worth carrying but not blindly: it needs the conditions to be genuinely independent. "Length divisible by 2 and by 4" needs only 4 states, because the second condition already implies the first, so checking for interaction before multiplying is part of the method.An NFA with n states is converted to an equivalent DFA. The number of DFA states is at most:
Show answer
Answer: C — 2ⁿ
2ⁿ. A DFA state in the subset construction is a set of NFA states — the set the NFA could currently be in — and there are 2ⁿ subsets of an n-element set. The bound is attained, not merely theoretical: the "third symbol from the end" language has a 4-state NFA and a minimal DFA of 8, and the k-th-from-the-end version reaches 2^k. What matters conceptually is that this is a statement about size only: both models recognise exactly the regular languages, so nondeterminism never lets an NFA accept a language no DFA can.To complement the language of an NFA, the correct procedure is:
Show answer
Answer: B — Convert to a DFA, swap there, and convert back if needed
The swap trick works for a DFA, where each string drives exactly one computation, so flipping the accepting set inverts membership precisely. An NFA accepts when any computation succeeds, so flipping its accepting set produces a machine that accepts when some path fails — not the complement. Hence option B: determinise first. Option D is wrong and worth being clear about: NFAs recognise exactly the regular languages, which are closed under complement — the difficulty is the cost of the construction, not its existence. That distinction between "closed under" and "cheap to compute" is the real content here.The cleanest way to prove that {aⁿbⁿ : n ≥ 0} is not regular is to observe that:
Show answer
Answer: B — The strings a, aa, aaa, … are pairwise distinguishable, so there are infinitely many classes
By Myhill–Nerode, a language is regular exactly when the number of equivalence classes is finite. Here aⁱ and aʲ with i ≠ j are separated by the suffix bⁱ, which completes the first into the language and the second out of it — so every one of a, aa, aaa, … lies in a class of its own and there are infinitely many classes. One line, no case analysis. Option A is not an argument but the thing to be proved. Option C is a true statement that proves nothing, since every regular language is also context free. Option D is plainly insufficient — ab is infinite and perfectly regular.Regular languages are closed under which of the following? (More than one may be correct.)
Show answer
Answer: A — Complement; B — Intersection; C — Kleene star; D — Reversal
All four. Union, concatenation and star come free from the definition of a regular expression; complement comes from swapping a DFA's accepting states; intersection follows either from the product construction or from De Morgan applied to the first two; and reversal from reversing every transition of an NFA and exchanging start and accepting states. This closure is unusually generous, and the reason to notice it is the contrast with context-free languages, which are closed under union, concatenation and star but not under intersection or complement. An "all of the above" answer is correct here and would be wrong for CFLs — that asymmetry is what the next chapter is built on.Two regular expressions are equivalent if and only if:
Show answer
Answer: B — Their minimal DFAs are identical up to renaming of states
Myhill–Nerode makes the minimal DFA unique for a language, so two expressions denote the same language exactly when they minimise to the same machine. That turns equivalence from a staring contest into a decision procedure: build an NFA for each, determinise, minimise, compare. Option D fails because NFAs are not canonical — the same language has many NFAs of many sizes, and equal counts prove nothing either way. The uniqueness of the minimal DFA is also why DFA equivalence is decidable, a fact worth holding on to, because the corresponding question for context-free grammars is undecidable.