Theory of Computation — taught by machines you can run
Unit-I: automata, regular expressions and the pumping lemma. Below are live simulators — type any string and watch the DFA step through it, or press play and let the animation run itself.
01Central Concepts — Alphabet, String, Language
An alphabet Σ is a finite set of symbols. A string is a finite sequence of symbols. A language is a set of strings over Σ. Automata are machines that decide membership in a language.
Three symbols that trip everyone up
| Symbol | What it is | Cardinality |
|---|---|---|
| ∅ | The empty set — a language with no strings | 0 strings |
| ε | The empty string — a string of length 0 | 1 string |
| {ε} | The language containing the empty string | 1 string |
02Deterministic Finite Automata (DFA)
A DFA = 5-tuple (Q, Σ, δ, q₀, F): states, alphabet, transition function, start state, accept states. Deterministic = exactly one move per input symbol — the machine can never be in two states at once.
Four designs, one recipe (design → draw → test)
Ends with 01
A = nothing useful yet · B = last symbol was 0 · C = just read 01 (accept). On 0 from C, go back to B (the "0" might start a new 01).
Starts with 01
After the first char goes wrong, jump to a dead state qd that eats everything. A dead state is not accepting and has no way out.
Even zeros AND even ones
Track parity of each count in the state itself: EE, OE, EO, OO. A 0 flips the first letter, a 1 flips the second.
Binary numbers divisible by 3
State = current remainder. Reading bit b: new = (2·old + b) mod 3. Accept only state 0. Try 10110 (=22, remainder 1 → reject).
03Nondeterministic Finite Automata (NFA)
An NFA may have zero, one, or many moves for a given symbol. It accepts if any path ends in an accept state. Conceptually it explores all paths in parallel — the active state is a set.
Subset construction — NFA → DFA, one set becomes one DFA state
| DFA state (subset) | on 0 | on 1 | accept? |
|---|---|---|---|
| A = {q₀} | {q₀,q₁} = B | {q₀} = A | no |
| B = {q₀,q₁} | {q₀,q₁} = B | {q₀,q₂} = C | no |
| C = {q₀,q₂} | {q₀,q₁} = B | {q₀} = A | yes (q₂ ∈ C) |
The DFA you get is exactly the "ends in 01" machine from section 2 — every NFA has an equivalent DFA, so the two formalisms recognise the same class: the regular languages.
04ε-NFA — Free Moves
An ε-NFA adds ε-transitions: moves you can take for free, without consuming any input. The machine can always be in the ε-closure of its current state set.
05Regular Expressions — and the bridge to Automata
Regular expressions are a notation for regular languages. Kleene's theorem: something is regular iff it can be described by a regex — and every regex can be mechanically converted into an NFA (Thompson's construction), and vice-versa.
Identity laws (memorise — exam gold)
| ∅R = R∅ = ∅ | R + ∅ = R | εR = Rε = R |
| R + R = R | R*R* = R* | (R*)* = R* |
| RR* = R*R = R⁺ | ∅* = ε | ε* = ε |
| R + R* = R* | (R₁R₂)*R₁ = R₁(R₂R₁)* | (R₁+R₂)* = (R₁*R₂*)* |
Patterns → regexes
| Language | Regex |
|---|---|
| ends in 01 | (0+1)*01 |
| starts with 1 | 1(0+1)* |
| exactly two 0s | 1*0 1*0 1* |
| even number of 0s | (1*01*0)* 1* |
| no two 1s together | (0+10)*(ε+1) |
| contains 010 | (0+1)*010(0+1)* |
Regexes → patterns
| Regex | Language (words of length ≤ 2) |
|---|---|
| 0*10* | {10, 010, 100, 0100, …} — exactly one 1 |
| (00)* | {ε, 00, 0000, …} — even-length all-zeros |
| (0+1)01 | {001, 101} |
| 0*+1* | {ε, 0, 00, 1, 11, …} — all 0s OR all 1s |
0+10 means (0) or (10), not (0+1)0. Always bracket carefully!06Thompson's Construction — Regex → NFA, built from 3 pieces
Every regex is assembled from tiny NFAs with a union (parallel), concat (series), and star (loop) gadget. Building (0+1)*01 uses all three.
07Pumping Lemma — Proving a Language is NOT Regular
The pump lemma says: in any regular language, sufficiently long strings can be pumped — a middle part repeats, and the result is still in the language. To prove non-regularity, show a string that can't be pumped without breaking the language.
The lemma (memorise the 3 conditions)
If L is regular, ∃ pumping length n such that every w ∈ L with |w| ≥ n can be split w = xyz where: 1. |xy| ≤ n · 2. y ≠ ε · 3. xyiz ∈ L for all i ≥ 0.
08Summary Sheet & 5 Near-Certain Questions
| Concept | One-line truth |
|---|---|
| DFA | One state at a time; total, deterministic δ |
| NFA | Set of states; may have ε moves; accepted if any path accepts |
| NFA → DFA | Subset construction (2|Q| states worst case) |
| Regex ↔ NFA | Thompson / Kleene; both describe exactly the regular languages |
| Closure | Regular languages close under ∪ · · * ∩ ¬ R homomorphism |
| Pumping | Proves non-regularity only |