The Timpson Lyceum seal

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 ε\varepsilon-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 AA proves AA 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:

Closure under union. Given NFAs N1,N2N_1, N_2 for A1,A2A_1, A_2, add a new start state q0q_0 with ε\varepsilon-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 N1N_1 to the start state of N2N_2 via an ε\varepsilon-transition, and un-mark N1N_1'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 N1N_1 or jump.

Closure under star. Add a new start state q0q_0 that is also an accept state (so ε\varepsilon is accepted), with an ε\varepsilon-transition to the old start state, and add ε\varepsilon-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 AA and toggle the accept states — the new accept set is Q∖FQ \setminus F. Every state that was accepting becomes non-accepting and vice versa, so the machine accepts exactly the strings AA rejected.

Closure under intersection. Free from De Morgan's laws: A1∩A2=A1‾∪A2‾‾A_1 \cap A_2 = \overline{\overline{A_1} \cup \overline{A_2}}. Since regular languages are closed under union and complement, they are closed under intersection. (The set operations ∩,∪,  ⋅  ‾\cap, \cup, \overline{\;\cdot\;} behave exactly like logical ∧,∨,¬\wedge, \vee, \lnot.)

Non-regular languages (preview). The language { 0n1n:n≥0 }\{\,0^n 1^n : n \ge 0\,\} is not regular. Intuition via contradiction: if a DFA with kk states accepted it, then reading 0k0^k forces a repeated state, so the computation contains a loop. Pumping that loop extra times yields a string with too many 00s 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. RR is a regular expression if it is one of:

  1. a symbol aa from the alphabet Σ\Sigma,
  2. ε\varepsilon (the empty string),
  3. ∅\varnothing (the empty set),
  4. R1∪R2R_1 \cup R_2 for regular expressions R1,R2R_1, R_2,
  5. R1R2R_1 R_2 (concatenation),
  6. R1∗R_1^{*} (star).

Notation and precedence. Σ\Sigma abbreviates (0∪1)(0 \cup 1) over the binary alphabet, so Σ∗\Sigma^{*} is all binary strings. Precedence, like arithmetic, is star, then concatenation, then union (star ≈\approx exponent, concatenation ≈\approx multiply, union ≈\approx add).

Algebraic identities (ε\varepsilon behaves like 11, ∅\varnothing like 00):

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 (ab)∪a(ab) \cup a 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:

ab  =  (NFA for a)  →ε  (NFA for b)(concatenation: link accept→start, drop old accepts)(ab)∪a  =  q0  →ε  {Nab, Na}(union: new start with two ε-branches)((ab)∪a)∗  =  q0′  (accept)  →ε  N∪,F→εq0′(star: accepting new start, loop accepts→start)\begin{aligned} ab \;&=\; (\text{NFA for } a)\;\xrightarrow{\varepsilon}\;(\text{NFA for } b) &&\text{(concatenation: link accept}\to\text{start, drop old accepts)} \\ (ab)\cup a \;&=\; q_{0}\;\xrightarrow{\varepsilon}\;\{N_{ab},\,N_{a}\} &&\text{(union: new start with two } \varepsilon\text{-branches)} \\ \big((ab)\cup a\big)^{*} \;&=\; q_{0}'\;(\text{accept})\;\xrightarrow{\varepsilon}\;N_{\cup},\quad F \xrightarrow{\varepsilon} q_{0}' &&\text{(star: accepting new start, loop accepts}\to\text{start)} \end{aligned}

Reading off the result: build a two-state machine accepting aa and another accepting bb, splice them with an ε\varepsilon-transition to get abab, build a fresh machine for aa, add a new start state with ε\varepsilon-arrows into both pieces to realize the union, and (for the star) add an accepting start state that ε\varepsilon-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