Recall warm-up
- What is the difference between ∅ and {ε}?
Stuck? Peek at 0.3.2 Σᵏ, Σ*, Σ⁺ and languages
- |Σᵏ| = |Σ|ᵏ; Σ⁰ = {ε}; Σ* = ⋃ Σᵏ (k ≥ 0); Σ⁺ = Σ* − {ε}.
- #strings of length ≤ n over k symbols = (kⁿ⁺¹ − 1)/(k − 1); binary: 2ⁿ⁺¹ − 1.
- Language = any subset of Σ*. ∅ (no strings) ≠ {ε} (one string). Exactly r of one symbol in length n (binary): C(n, r).
- Shortlex order lists every string at a finite position.
- How many functions are there from a 6-element set to a 3-element set?
Stuck? Peek at 0.2.2 Functions, relations and equivalence classes
- Relation ⊆ A × B. Function: every input exactly one output. Partial function: some inputs have none.
- #functions A→B = |B|^|A|. #one-to-one (|A| ≤ |B|) = |B|·(|B|−1)···. #relations on n-set = 2^(n²).
- Equivalence = reflexive + symmetric + transitive. Classes partition the set; number of classes = index.
- Finer relation (refinement) ⇒ more classes; every fine class sits inside a coarse class.
- A machine with 4 modes reads 4 symbols. Must it repeat a mode?
Stuck? Peek at 0.2.4 Pigeonhole principle
- n + 1 objects in n boxes ⇒ some box has ≥ 2.
- N objects in k boxes ⇒ some box has ≥ ⌈N/k⌉. To force m in a box: (m−1)k + 1 objects.
- Machine with n modes, input length ≥ n ⇒ some mode repeats ⇒ a loop in the input.
The Hook
Back to the even/odd machine from Lesson 0.1.1. It had two modes, EVEN and ODD, and a rule for every (mode, symbol) pair. It read the input once, left to right, never went back, never wrote anything down — and still answered correctly for inputs of any length.
That is exactly how the text-search inside your editor, the lexer inside a compiler, and the controller inside a lift work. They are all the same mathematical object: a Deterministic Finite Automaton (DFA). This lesson gives the modes their real name — states — and writes the machine down so precisely that there is no room for doubt.
Predict First
Over Σ = {a, b}, a machine must accept exactly the strings that start with a. It must have a rule for every state and every symbol. How many states do you think it needs?
Core Concept
Prediction check
Answer: 3. One state for “nothing read yet” (the start), one for “first symbol was a — accept whatever follows”, and one for “first symbol was b — reject whatever follows”. That third one is a dead state: once you enter it you can never leave and never accept. Most people guess 2 because they forget it.
States
A state is a mode of a finite-memory machine: a summary of everything the machine needs to remember about the input read so far. The machine has a fixed, finite set of them, chosen before any input arrives.
The formal definition (5-tuple)
- Q — a finite set of states;
- Σ — the input alphabet;
- δ : Q × Σ → Q — the transition function: in state q reading symbol a, go to δ(q, a);
- q₀ ∈ Q — the start state;
- F ⊆ Q — the set of accepting (final) states.
“Deterministic” means δ is a (total) function: for every state and every symbol there is exactly one next state. No choices, no missing rules.
| Part | Symbol | Even-a’s DFA |
|---|---|---|
| states | Q | {E, O} |
| alphabet | Σ | {a, b} |
| transition function | δ : Q × Σ → Q | 4 entries (2 × 2) |
| start state | q₀ | E |
| accepting states | F | {E} |
How a DFA runs
- Start in q₀, with the head before the first symbol.
- Read one symbol a, move from the current state q to δ(q, a).
- Repeat until the input is used up.
- If the final state is in F, accept; otherwise reject.
A DFA always finishes: one step per symbol, so an input of length n takes exactly n steps. It never loops forever and never gets stuck.
Two ways to draw δ
Transition diagram: a labelled directed graph (Lesson 0.2.5). Nodes = states; an arrow labelled a from p to q means δ(p, a) = q; an arrow from nowhere marks q₀; a double circle marks an accepting state.
Transition table: one row per state, one column per symbol, entry = next state. Mark the start row with → and accepting rows with *.
| a | b | |
|---|---|---|
| →* E | O | E |
| O | E | O |
The dead (trap) state
A dead state is a non-accepting state whose every transition loops back to itself. Once entered, the input is rejected no matter what follows. It exists because δ must be total: when a string is already hopeless, the DFA still needs somewhere to go.
Many diagrams leave the dead state out to reduce clutter (any missing arrow means “go to the dead state”). That is only a drawing shortcut; the real DFA still has it.
Counting DFAs
With n states, alphabet size m, and a fixed start state: δ has n·m entries, each one of n states → nⁿᵐ choices; F is any subset → 2ⁿ choices. Total nⁿᵐ · 2ⁿ DFAs (multiply by n if the start state may also vary).
Putting it together
- A DFA is (Q, Σ, δ, q₀, F) with exactly one move per (state, symbol); it reads each symbol once and always halts.
- It accepts iff it ends in F; it accepts ε iff q₀ ∈ F.
- Missing arrows mean a dead state, and minimal-DFA counts include it.
Visual
The even-a’s DFA and the starts-with-a DFA are live below. Press Step to watch the highlighted state move; try the example chips.
States: E, O
Transitions: E>O: a; O>E: a; E>E: b; O>O: b
Transition table — even number of a's trace of "baba"
a b E ─b→ E ─a→ O ─b→ O ─a→ E end E ∈ F → ACCEPT
→*E O E trace of "ab"
O E O E ─a→ O ─b→ O end O ∉ F → REJECT
States: q0, q1, D
Transitions: q0>q1: a; q0>D: b; q1>q1: a,b; D>D: a,b
Transition table — starts with a
a b
→ q0 q1 D trace "ab": q0 ─a→ q1 ─b→ q1 ACCEPT
* q1 q1 q1 trace "ba": q0 ─b→ D ─a→ D REJECT (trapped)
D D D trace "ε": stays q0 ∉ F REJECTWorked Examples
Write the 5-tuple of the even-a’s DFA.
Show the full solution
Q = {E, O}, Σ = {a, b}, q₀ = E, F = {E}, δ(E,a) = O, δ(E,b) = E, δ(O,a) = E, δ(O,b) = O. Four entries = |Q|·|Σ| = 2·2 ✓.
Design a DFA over {0,1} accepting exactly the string 01. How many states?
Show the full solution
States: s (nothing read), p (read 0), f (read 01, accepting), D (dead). δ(s,0)=p, δ(s,1)=D, δ(p,1)=f, δ(p,0)=D, δ(f,0)=δ(f,1)=D, D loops. 4 states. Trace “01”: s→p→f accept. “010”: s→p→f→D reject. “1”: s→D reject. In general a single string of length k needs k + 2 states (k+1 progress states + dead).
How many DFAs exist with exactly 2 states {X, Y}, alphabet {a, b}, and X as the start state?
Show the full solution
δ has 2·2 = 4 entries, each X or Y: 2⁴ = 16. F ⊆ {X,Y}: 4 choices. Total 64. (These 64 DFAs accept far fewer than 64 different languages — many DFAs accept the same language.)
GATE Traps
- Forgetting the dead state when counting states. If some prefix makes acceptance impossible, a dead state is needed.
- δ must be defined for every (state, symbol) pair — a diagram with missing arrows is shorthand for arrows to a dead state.
- ε is accepted iff q₀ ∈ F. Check the start state whenever ε is involved.
- “DFA” vs “minimal DFA”: a question asking for states of a DFA has no unique answer; “minimal DFA” does.
Memory Hook
A DFA is a board game with no dice: from every square, each card you draw sends you to exactly one square. Double-ringed squares are the winning squares; the dead state is the jail with no exit.
Connect the Dots
States are Lesson 0.1.1’s modes; δ is a function of two inputs (0.2.2); the diagram is a labelled directed graph (0.2.5). Next lesson: what exactly is the set of strings a DFA accepts, and how do we follow a whole string through δ at once?
Self-Test
- MCQ
In a DFA M = (Q, Σ, δ, q₀, F), δ is a function from:
- Q → Σ
- Q × Σ → Q
- Q × Σ → P(Q)
- Σ → Q
- NAT
Minimum number of states of a DFA over {a,b} accepting exactly the strings that start with
ab?Write your answer before opening the key.
- MSQ
Which are true for every DFA?
- It halts after exactly |w| steps on input w
- It accepts ε iff its start state is accepting
- It may have two transitions on the same symbol from one state
- Its number of states is finite
- NAT
How many DFAs have 3 states {p, q, r}, alphabet {0}, and start state p?
Write your answer before opening the key.
- MCQ
A dead state is:
- an accepting state with self-loops
- a non-accepting state from which no accepting state is reachable
- the start state
- a state with no incoming arrows
Rule Card
- DFA = (Q, Σ, δ, q₀, F), δ : Q × Σ → Q total. One step per symbol; always halts.
- Accept iff the last state ∈ F. ε accepted ⇔ q₀ ∈ F.
- Dead state: non-accepting, all self-loops. GATE counts it in minimal-DFA questions.
- Exactly one string of length k: k + 2 states. #DFAs (n states, m symbols, fixed start) = nⁿᵐ · 2ⁿ.
Concept Ledger
- state
- DFA (Q, Σ, δ, q₀, F)
- transition function δ
- start state q₀
- accepting / final state, F
- transition diagram
- transition table
- dead / trap state
- deterministic (exactly one move)
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- ∅ has no strings; {ε} has exactly one string, the empty string.
- 3⁶ = 729.
- Yes — 5 moments, 4 modes.
Self-test answers
- B — One next state per (state, symbol).
- A: States do not output symbols.
- C: That allows a set of next states — not deterministic.
- D: The next state depends on the current state too.
- 4 — start, read a, read ab (accept forever), dead.
- ABD — Determinism forbids C.
- C: That would make δ not a function.
- 216 — 3^(3·1) · 2³ = 27 · 8 = 216.
- B — Once entered, acceptance is impossible.
- A: That would accept everything after.
- C: Unrelated.
- D: That is an unreachable state (Ch 1.3).
Flashcards
- 5-tuple of a DFA?
Reveal answer
(Q, Σ, δ, q₀, F): states, alphabet, transition function Q×Σ→Q, start state, accepting states. - When does a DFA accept ε?
Reveal answer
Exactly when q₀ ∈ F. - Does GATE count the dead state in “minimal DFA” questions?
Reveal answer
Yes, whenever the language needs one. - States needed for a DFA accepting exactly one string of length k?
Reveal answer
k + 2 (k+1 progress states + dead). - Number of DFAs with n states, m symbols, fixed start?
Reveal answer
nⁿᵐ · 2ⁿ
Exam shortcuts
- Quick dead-state check: is there a prefix after which no continuation can be accepted? If yes, the minimal DFA has a dead state — count it.