skip to content

questions

5

In a deterministic finite acceptor for badge sequences, what makes two of its states distinguishable rather than mergeable?

level: middleimportance: must knowfreq 62%

answer

  1. future behaviour, not arrival path
  2. look for a witness string
  3. empty suffix separates accepting from rejecting
  4. same verdict on every suffix
  5. Myhill-Nerode classes count the states

basics

~20 s

Two states are distinguishable when some remaining input is accepted from one and rejected from the other; that string is the witness. States with no such witness behave identically on every future input and can be merged without changing the accepted language.

solid answer

~40 s

A state of a deterministic acceptor carries no record of how you got there, so all that separates two states is what they do with the input still to come. States `p` and `q` are distinguishable when some suffix `w` drives one of them into an accepting state and the other into a non-accepting one; `w` is the distinguishing suffix, or witness. The empty suffix already separates any accepting state from any non-accepting state. If no suffix at all separates them, they are equivalent and can be collapsed into one state. Myhill-Nerode lifts this to the language itself: the equivalence classes of strings under `xw` and `yw` always agreeing on membership are exactly the states of the minimal acceptor, so the state count is a property of the badge language, not of anyone's firmware.

code

pseudocode · 14 lines
pseudocode
for each pair (p, q) of states
  if exactly one of p, q is accepting
    mark (p, q) with witness = empty string

repeat
  progress = false
  for each unmarked pair (p, q)
    for each letter a in alphabet
      if pair (delta(p, a), delta(q, a)) is marked
        mark (p, q) with witness = a followed by witness(delta(p, a), delta(q, a))
        progress = true
until progress is false

every pair still unmarked holds two equivalent states

go deeper

for a junior

Recall that a finite acceptor remembers nothing except which state it is in, and that its decision depends only on the input still to come.

for a middle

Explain distinguishability with a concrete witness string, name the empty suffix as the one that separates accepting from non-accepting states, and connect the class count to the minimal state count.

for a senior

Show how you would use witnesses in a real review: when two firmwares disagree, the separating string is the reproducible test case you hand back to the team that built the wrong machine.

for a principal

Frame state count as a property of the specified language rather than of an implementation, so that a debate about machine size becomes a debate about what the specification actually requires.

Two teams ship door-controller firmware, and both claim their controller opens on exactly the same badge sequences. One machine has six states, the other three. Comparing them state by state means nothing until you have a definition of when two states really are the same state. That definition is distinguishability, and every minimization result is built on it. ## A state is its future, not its past A deterministic finite acceptor is a finite set of states, an input alphabet, a total transition function, one start state and a set of accepting states. The moment the machine enters a state, the prefix that took it there is gone — the current state is the machine's entire memory. So everything a state can still contribute to the verdict is answered by one question: **for each possible remaining input, does the run end in an accepting state?** That gives the definition. States `p` and `q` are **distinguishable** when there exists a string `w` such that reading `w` from `p` ends accepting and reading `w` from `q` does not, or the reverse. Such a `w` is a **distinguishing suffix**, or witness — it is concrete evidence you can show in a review. When no string whatsoever separates them, `p` and `q` are **equivalent**, and merging them leaves the accepted language untouched. Two consequences fall straight out: - The **empty suffix** distinguishes any accepting state from any non-accepting one. Every minimization procedure therefore begins by separating those two groups. - The **prefixes that reached the states are irrelevant**. Two states arrived at by completely different badge histories are the same state if their futures agree. This is the point candidates most often miss. ## Myhill-Nerode: the language fixes the state count The **Myhill-Nerode theorem** applies the same relation to strings instead of states. Call two input strings `x` and `y` equivalent for a language `L` when, for every suffix `w`, `xw` is in `L` exactly when `yw` is. The theorem says a language is regular precisely when this relation has finitely many classes, and that the minimal deterministic acceptor has **one state per class**. So the minimum number of states is decided by the language, before anyone writes firmware. An implementation may carry extra states; it can never carry fewer. That is why minimization is a canonicalisation, not an optimisation trick. ## Worked example: two badge controllers Take the language of badge sequences that unlock a door once two valid scans have been seen, over the alphabet `v` (valid scan) and `x` (rejected scan). One team's firmware has six states: `A` (start, no valid scan yet), `D` (no valid scan yet, but an invalid one has been logged), `B` and `C` (one valid scan seen, reached by two different paths), and `E` and `F` (unlocked, accepting). | Pair | Distinguishing suffix | Verdict | |---|---|---| | `A` vs `B` | `v` | one further valid scan unlocks from `B` only — distinguishable | | `B` vs `E` | empty string | `E` accepts, `B` does not — distinguishable | | `A` vs `D` | none exists | equivalent: both still need two valid scans | | `E` vs `F` | none exists | equivalent: both accept every continuation | The six-state machine therefore collapses to three: still-need-two, still-need-one, unlocked. The other team's three-state firmware is the same machine with different state names. ## Finding the witnesses mechanically You do not have to guess suffixes. Mark every pair whose members disagree on acceptance, then repeatedly mark any pair that some letter sends to an already-marked pair, recording that letter in front of the shorter witness. When a pass marks nothing new, the unmarked pairs are exactly the equivalent ones, and each marked pair carries a concrete separating string. This is the pairwise view of the same fact that partition refinement computes block by block. ## Traps this catches in review - Arguing that two states differ because different badge histories reach them. Histories are not observable to the machine. - Checking only acceptance status. Two non-accepting states can still be miles apart — the witness is just longer than the empty string. - Assuming a bigger machine accepts more. Six states and three states here accept exactly the same set of sequences; the extra states are duplicated futures. - Declaring equivalence after checking one letter. Equivalence is a claim about every suffix, which is why the marking loop runs to a fixed point.

  • Which suffix always distinguishes an accepting state from a non-accepting one?
    The empty string. Reading nothing leaves each state where it is, so one of them is accepting and the other is not, which is exactly the definition of a witness. That is why every minimization procedure starts by separating accepting from non-accepting states before it looks at any transition.
  • Why is 'reached by different prefixes' no evidence that two states differ?
    Because a deterministic acceptor keeps no memory beyond its current state. Once the machine is in a state, the prefix has been forgotten, so it cannot influence any later decision. Two states reached by unrelated badge histories are the same state whenever every remaining input produces the same verdict from both.
  • What is the fewest states any deterministic acceptor for a language can have?
    One per Myhill-Nerode class of the language. If a machine had fewer, two strings from different classes would land on the same state; the suffix that separates those classes would then get the same verdict from both, contradicting the fact that one extension is in the language and the other is not.

Two filing clerks are interchangeable if no request you could hand them is answered differently; how each got to their desk this morning is not part of the test.

saying these in an interview costs you the question

  • Claims two states differ because different input prefixes reach them
  • Thinks only accepting status decides whether two states merge
  • Says a machine with more states accepts more strings
  • Declares equivalence after comparing a single input letter
  • Believes merging equivalent states can change the accepted language
open as a page

How does partition refinement collapse a six-state badge acceptor into the smallest deterministic machine accepting the same sequences?

level: middleimportance: should knowfreq 48%

basics

~20 s

Start with two blocks, accepting states and non-accepting states, then repeatedly split any block whose members send some input letter into different blocks. When no split applies, each remaining block becomes one state of the minimal machine.

open as a page

Why does partition refinement alone fail to give the smallest deterministic acceptor when some of its states are unreachable?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Refinement merges states that behave identically; it never deletes states. An unreachable state can be distinguishable from every reachable one, so it survives as its own block and inflates the result, even though no input can visit it and the accepted language is unchanged.

open as a page

When two teams must keep independently written badge acceptors in agreement forever, what does adopting the canonical minimal machine as the shared specification cost?

level: principalimportance: should knowfreq 33%

basics

~20 s

You gain a unique object: for one language the minimal acceptor is the same machine up to renaming, so agreement becomes an identity check. You pay in readability, unstable diffs, and a contract that covers acceptance only, never outputs or timing.

open as a page

Why can no complete deterministic acceptor of badge frames exactly n symbols long use fewer than n+2 states?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

Because the language has n+2 Myhill-Nerode classes: one per prefix length from 0 to n, plus one for everything already too long. A machine with fewer states would place two classes on one state and then give their separating suffix the same verdict, which is impossible.

open as a page