The Timpson Lyceum · Computation Theory
Lecture 6 (Computation Theory) Nondeterministic Finite Automata and Regular Expressions
Overview
This lecture closes out the theory of finite automata and opens the study of regular expressions. Having already established that NFAs and DFAs are equivalent in power, we use the flexibility of NFAs to prove that the regular languages are closed under the three regular operations — union, concatenation, and star — plus complement and intersection. We then preview how to argue that a language is not regular, using the looping (pumping) intuition. Finally, we define regular expressions precisely and prove one direction of their equivalence with finite automata: every regular expression denotes a regular language. The throughline is that all of these tools are just different ways of certifying that a language is regular.
Key Concepts
DFA vs. NFA (recap). A DFA (deterministic finite automaton) must have exactly one transition out of every state for every input symbol — no missing arrows and no two arrows on the same symbol from one state. An NFA (nondeterministic finite automaton) may omit arrows (a missing transition means that computation branch dies), may have several arrows on the same symbol, and may take -transitions (move without consuming input). An NFA accepts a string if some computation path reaches an accept state. NFAs and DFAs recognize exactly the same class of languages, so building either one for a language proves is regular.
Closed operation. A set is closed under an operation if applying it never escapes the set (e.g. the natural numbers are closed under addition but not subtraction). The regular operations are:
- Union — strings in either language ("or").
- Concatenation — a prefix from followed by a suffix from .
- Star — zero or more strings of concatenated; always includes .
Closure under union. Given NFAs for , add a new start state with -transitions to the old start states (which stop being start states). The combined machine guesses which sub-machine to run.
Closure under concatenation. Connect every accept state of to the start state of via an -transition, and un-mark 's accept states. Nondeterminism "guesses" where to split the string; the old accept states keep their transitions so the machine can choose either to keep reading in or jump.
Closure under star. Add a new start state that is also an accept state (so is accepted), with an -transition to the old start state, and add -transitions from every old accept state back to the old start state (so the machine can loop and restart any number of times).
Closure under complement. Easiest with a DFA: take a DFA for and toggle the accept states — the new accept set is . Every state that was accepting becomes non-accepting and vice versa, so the machine accepts exactly the strings rejected.
Closure under intersection. Free from De Morgan's laws: . Since regular languages are closed under union and complement, they are closed under intersection. (The set operations behave exactly like logical .)
Non-regular languages (preview). The language is not regular. Intuition via contradiction: if a DFA with states accepted it, then reading forces a repeated state, so the computation contains a loop. Pumping that loop extra times yields a string with too many s that the machine still accepts — but that string is not in the language, a contradiction. This is the seed of the pumping lemma.
Regular expression. Defined inductively. is a regular expression if it is one of:
- a symbol from the alphabet ,
- (the empty string),
- (the empty set),
- for regular expressions ,
- (concatenation),
- (star).
Notation and precedence. abbreviates over the binary alphabet, so is all binary strings. Precedence, like arithmetic, is star, then concatenation, then union (star exponent, concatenation multiply, union add).
Algebraic identities ( behaves like , like ):
- (any starred expression generates at least )
- Concatenation distributes over union: .
Regular expressions denote regular languages. The language generated by any regular expression is regular, proved by converting each of the six cases to an NFA: cases 1–3 are tiny base machines, and cases 4–6 reuse the union/concatenation/star constructions above.
Worked Example
Goal: Convert the regular expression into an NFA mechanically, by applying the six conversion rules — base machines for symbols, then concatenation, union, and (to illustrate) star.
State the constructions used:
Reading off the result: build a two-state machine accepting and another accepting , splice them with an -transition to get , build a fresh machine for , add a new start state with -arrows into both pieces to realize the union, and (for the star) add an accepting start state that -loops back from the accept states. The resulting NFA is far larger than necessary, but it is produced purely by the rules — proving every regular expression has an equivalent NFA, hence denotes a regular language.
Summary
- NFAs are no more powerful than DFAs, so building either certifies a language is regular; NFAs just make the closure proofs trivial.
- Regular languages are closed under union (new -branching start), concatenation (-link accepts to next start), and star (accepting new start that -loops back).
- They are also closed under complement (toggle a DFA's accept states) and intersection (via De Morgan: ).
- Not every language is regular: fails because any finite machine must loop on long inputs, and that loop can be pumped to accept illegal strings — the pumping intuition.
- A regular expression is built inductively from symbols, , and using union, concatenation, and star, with precedence star concatenation union; acts like and like (and ).
- Every regular expression denotes a regular language, shown by converting its six cases into an equivalent NFA; the converse (every regular language has a regular expression) comes next.