CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 1 · Finite Automata

Lesson 1.1.1 · Item 15 of 91

States and the DFA

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. 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.

    Read lesson 0.3.2

  2. 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.

    Read lesson 0.2.2

  3. 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.

    Read lesson 0.2.4

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.

q0
nothing read yet
q1
first symbol was a — accept whatever follows
D
first symbol was b — hopeless forever
Three different situations ⇒ three states. The dead state is the one people forget.

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.

input so far
b a b a b b a
compress
summary
“even number of a’s”
name it
state
E
A state is a name for a summary of everything read so far.

The formal definition (5-tuple)

DFA M = (Q, Σ, δ, q₀, F) where
  • 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.

PartSymbolEven-a’s DFA
statesQ{E, O}
alphabetΣ{a, b}
transition functionδ : Q × Σ → Q4 entries (2 × 2)
start stateq₀E
accepting statesF{E}
The 5-tuple, filled in.

How a DFA runs

  1. Start in q₀, with the head before the first symbol.
  2. Read one symbol a, move from the current state q to δ(q, a).
  3. Repeat until the input is used up.
  4. 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.

steps illustration
A DFA run: exactly |w| steps, never stuck, never looping.

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 *.

ab
→* EOE
OEO
The same machine as a table: → marks the start row, * marks accepting rows. Every cell has exactly one entry.

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.

Convention for GATE: “number of states in the minimal DFA” includes the dead state whenever the language needs one. Some textbooks draw “partial DFAs” without it; GATE answer keys count it.
Drawn as a shortcut
q0 —a→ q1 · no arrow for b
The real DFA
q0 —b→ D · D loops on a and b
A missing arrow in a drawing means “go to the dead state”. GATE counts D.

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).

entries of δ
n · m
choices per entry
n
tables
nⁿᵐ
× accepting sets
2ⁿ
n = 2, m = 2
16 × 4 = 64
Counting DFAs with a fixed start state.

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.

Even number of a’s

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
Starts with a (with dead state D)

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       REJECT

Worked Examples

Easy

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 ✓.

Medium

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).

GATE-level

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

  1. MCQ

    In a DFA M = (Q, Σ, δ, q₀, F), δ is a function from:

    1. Q → Σ
    2. Q × Σ → Q
    3. Q × Σ → P(Q)
    4. Σ → Q
  2. 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.

  3. MSQ

    Which are true for every DFA?

    1. It halts after exactly |w| steps on input w
    2. It accepts ε iff its start state is accepting
    3. It may have two transitions on the same symbol from one state
    4. Its number of states is finite
  4. NAT

    How many DFAs have 3 states {p, q, r}, alphabet {0}, and start state p?

    Write your answer before opening the key.

  5. MCQ

    A dead state is:

    1. an accepting state with self-loops
    2. a non-accepting state from which no accepting state is reachable
    3. the start state
    4. 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

  1. ∅ has no strings; {ε} has exactly one string, the empty string.
  2. 3⁶ = 729.
  3. Yes — 5 moments, 4 modes.

Self-test answers

  1. 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.
  2. 4 — start, read a, read ab (accept forever), dead.
  3. ABD — Determinism forbids C.
    • C: That would make δ not a function.
  4. 216 — 3^(3·1) · 2³ = 27 · 8 = 216.
  5. B — Once entered, acceptance is impossible.
    • A: That would accept everything after.
    • C: Unrelated.
    • D: That is an unreachable state (Ch 1.3).

Flashcards

  1. 5-tuple of a DFA?
    Reveal answer(Q, Σ, δ, q₀, F): states, alphabet, transition function Q×Σ→Q, start state, accepting states.
  2. When does a DFA accept ε?
    Reveal answerExactly when q₀ ∈ F.
  3. Does GATE count the dead state in “minimal DFA” questions?
    Reveal answerYes, whenever the language needs one.
  4. States needed for a DFA accepting exactly one string of length k?
    Reveal answerk + 2 (k+1 progress states + dead).
  5. Number of DFAs with n states, m symbols, fixed start?
    Reveal answernⁿᵐ · 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.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.