CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 1 · Finite Automata

Lesson 1.3.3 · Item 26 of 91

Myhill–Nerode theorem

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

On this page

Recall warm-up

  1. What are the two methods for minimizing a DFA?
    Stuck? Peek at 1.3.2 Partition and table-filling methods
    • Partition: remove unreachable; P₀ = {F, Q−F}; split by signatures w.r.t. previous partition; stop when stable.
    • Table filling: n(n−1)/2 cells; mark (F, non-F); propagate “successor pair marked ⇒ mark”; unmarked = equivalent.
    • Count by distinct futures: list situations with different accepted continuations, include dead / satisfied states.
    • Exactly k of a symbol: k + 2 states; at least k: k + 1; at most k: k + 2.

    Read lesson 1.3.2

  2. Minimal DFA for strings with exactly 3 a’s over {a,b}?
    Stuck? Peek at 1.3.2 Partition and table-filling methods
    • Partition: remove unreachable; P₀ = {F, Q−F}; split by signatures w.r.t. previous partition; stop when stable.
    • Table filling: n(n−1)/2 cells; mark (F, non-F); propagate “successor pair marked ⇒ mark”; unmarked = equivalent.
    • Count by distinct futures: list situations with different accepted continuations, include dead / satisfied states.
    • Exactly k of a symbol: k + 2 states; at least k: k + 1; at most k: k + 2.

    Read lesson 1.3.2

  3. What is the index of an equivalence relation?
    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

The Hook

Minimization needed a DFA to start with. But GATE often gives only a description: “the language of all strings where …”. And sometimes the honest answer is “no DFA exists at all”. Is there a way to count states — or prove none suffice — directly from the language? Yes: group strings (not states) by their futures. This is the Myhill–Nerode theorem, and it explains why minimization works.

Predict First

Language L = { aⁿbⁿ | n ≥ 0 }. Do the strings a and aa have the same “future”? That is, is there a continuation z such that az ∈ L but aaz ∉ L?

Core Concept

Prediction check

Yes: z = b. ab ∈ L but aab ∉ L. In fact aⁱ and aʲ (i ≠ j) are always separated by z = bⁱ. So infinitely many strings have pairwise different futures — and that will mean no DFA can exist for L.

prefixz = bz = bbz = bbb
aab ✓abb ✗abbb ✗
aaaab ✗aabb ✓aabbb ✗
aaaaaab ✗aaabb ✗aaabbb ✓
For aⁿbⁿ each prefix aⁱ needs a different future: infinitely many classes.

The Myhill–Nerode relation

For a language L ⊆ Σ*, define x ≡_L y iff for every z ∈ Σ*: xz ∈ L ⇔ yz ∈ L.

“x and y need the same continuations.” It is an equivalence relation. It is also right-invariant: if x ≡_L y then xa ≡_L ya for every symbol a.

x ≡_L y
for every z: xz ∈ L ⇔ yz ∈ L
right-invariant
x ≡ y ⇒ xa ≡ ya
Group strings by their futures.

The theorem

Myhill–Nerode theorem. L is regular ⇔ ≡_L has finitely many classes (finite index). Moreover, the number of classes equals the number of states of the minimal DFA for L.

Why: in any DFA for L, strings ending in the same state have the same future, so #states ≥ #classes. And the classes themselves form a DFA: state [x], move [x] ─a→ [xa], start [ε], accept the classes inside L. That DFA has exactly #classes states, so it is minimal.

classes of ≡_L
[x]
states
[x] —a→ [xa]
minimal DFA
#states = #classes
The classes themselves form the minimal DFA.

Two uses

  • Count minimal states: find a list of strings that are pairwise distinguishable (each pair separated by some z) and show every string falls into one of their classes. The list size = minimal state count.
  • Prove a language is not regular: find infinitely many strings, pairwise distinguishable. Then the index is infinite, so no DFA exists. This is our first rigorous proof of non-regularity.
finite index
count classes → minimal DFA size
infinite index
not regular — no DFA exists
Two uses of the theorem.

Example: ends with ab

Classes: [ε] (strings ending in neither a nor ab, including ε, “b”, “abb”), [a] (ending in a), [ab] (ending in ab). Pairwise: ε vs a: z = b (ab ∈ L, b ∉ L). ε vs ab: z = ε. a vs ab: z = ε. Three classes ⇒ minimal DFA has 3 states.

Myhill–Nerode classes with sample strings.
Myhill–Nerode classes with sample strings.

Putting it together

  • x ≡_L y when every continuation treats them alike.
  • Regular ⇔ finitely many classes; the count is the minimal DFA size (dead class included).
  • Infinitely many pairwise-distinguishable strings prove a language is not regular.

Visual

L = { w ∈ {a,b}* : w ends with ab }

 class      sample strings          continuations z that lead into L
 [ε]        ε, b, bb, abb, aab b    z ends with ab  (e.g. "ab")
 [a]        a, ba, aba, aa          z = b, or z ends with ab
 [ab]       ab, bab, aab            z = ε, or z ends with ab
 three different "future sets" → 3 states → same as 1.2.3's DFA

L = { aⁿbⁿ } :    ε   a   aa   aaa   aaaa ...
 separating z:     ε   b   bb   bbb   bbbb   (aⁱbⁱ ∈ L, aʲbⁱ ∉ L for j ≠ i)
 infinitely many classes  →  NOT regular

Worked Examples

Easy

L = strings over {a,b} with an even number of a’s. List the Myhill–Nerode classes.

Show the full solution

[ε] = even a’s, [a] = odd a’s. ε vs a separated by z = ε. Any string is in one of the two. Index 2 ⇒ 2 states.

Medium

L = { w : |w| ≥ 2 } over {a}. Find the classes.

Show the full solution

[ε], [a], [aa] — ε needs ≥ 2 more, a needs ≥ 1 more, aa needs nothing. Pairwise separated: ε vs a by z = a; a vs aa by z = ε; ε vs aa by ε. All longer strings fall in [aa]. 3 classes.

GATE-level

Prove that L = { w ∈ {a,b}* : |w|ₐ = |w|_b } is not regular using Myhill–Nerode.

Show the full solution

Take the infinite family aⁱ (i = 0, 1, 2, …). For i ≠ j choose z = bⁱ: aⁱbⁱ ∈ L, aʲbⁱ ∉ L. So the aⁱ are pairwise in different classes: infinitely many classes ⇒ not regular. ∎ (Memory link: the machine would need to remember the difference #a − #b, an unbounded fact — Lesson 0.1.1.)

GATE Traps

  • The relation is about continuations z appended on the right, not prefixes.
  • One separating z is enough to put two strings in different classes; to put them in the same class you must argue for all z.
  • The class count includes the “dead” class (strings with no accepted continuation), when it exists.
  • Infinite index ⇒ not regular. A language can be infinite yet have finite index (e.g. Σ*, index 1).

Memory Hook

Myhill–Nerode = group strings by their futures. Finitely many futures = finite memory = regular.

Connect the Dots

Myhill–Nerode ties the whole of Phase 1 together: states are just names for “futures”; minimization finds them from a machine; the theorem finds them from the language; and infinitely many futures means no finite machine. One small topic remains in Phase 1: finite machines that produce output instead of just yes/no.

Self-Test

  1. MCQ

    x ≡_L y means:

    1. x and y have the same length
    2. for all z, xz ∈ L ⇔ yz ∈ L
    3. x and y are both in L
    4. for all z, zx ∈ L ⇔ zy ∈ L
  2. NAT

    Index of ≡_L for L = strings over {a,b} containing bb?

    Write your answer before opening the key.

  3. MSQ

    Which follow from the Myhill–Nerode theorem?

    1. L regular ⇒ ≡_L has finite index
    2. Finite index ⇒ L regular
    3. #classes = #states of the minimal DFA
    4. Every infinite language has infinite index
  4. MCQ

    To prove L non-regular with Myhill–Nerode you need:

    1. one string not in L
    2. infinitely many pairwise distinguishable strings
    3. a DFA for the complement
    4. two strings with the same future

Rule Card

  • x ≡_L y ⇔ ∀z: xz ∈ L ⇔ yz ∈ L. Right-invariant equivalence.
  • L regular ⇔ finite index; index = #states of minimal DFA (incl. dead class).
  • Infinitely many pairwise distinguishable strings ⇒ not regular. aⁿbⁿ: strings aⁱ separated by bⁱ.

Concept Ledger

  • Myhill–Nerode relation ≡_L
  • right-invariant
  • finite index
  • Myhill–Nerode theorem
  • non-regular language

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. Partition refinement and table filling.
  2. 5.
  3. Its number of equivalence classes.

Self-test answers

  1. B — Same right continuations.
    • A: Length is irrelevant.
    • C: Being in L is only z = ε.
    • D: Continuations go on the right.
  2. 3 — No progress, last symbol b (one b), already contains bb.
  3. ABC — Both directions plus the count.
    • D: Σ* is infinite with index 1.
  4. B — Infinitely many classes.
    • A: Says nothing.
    • C: Would prove L regular.
    • D: Irrelevant.

Flashcards

  1. Myhill–Nerode theorem?
    Reveal answerL is regular iff ≡_L has finitely many classes; the number of classes = states of the minimal DFA.
  2. How do you prove aⁿbⁿ is not regular with Myhill–Nerode?
    Reveal answerThe strings aⁱ are pairwise distinguishable (z = bⁱ), so there are infinitely many classes.
  3. Can an infinite language have finite index?
    Reveal answerYes — e.g. Σ* has index 1.

Ready for the next idea?

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