Theory of Computation · Week 1 · Lesson 0002 of 7
Designing and comparing DFAs
A state meaning gives both the transitions and the accepting states.
Choose what to remember, verify every transition, and compare two machines for inputs of any length.
1Warm-up
2Choose a state meaning
A prefix is an initial segment of a string. A state invariant is a statement about the prefix read so far that is true each time the machine reaches a given state. Checking the start and each transition proves the invariant for every prefix.
For “starts and ends with the same bit,” use a start state S and states 00, 01, 10, 11. Each two-bit label records the first bit and the current last bit. After the first symbol, keep the first bit and replace the last bit with the symbol read. Accept 00 and 11. If the language explicitly includes ε, also accept S. The input 0 moves from S to 00 and is accepted.
A substring occupies consecutive positions. To recognize strings with no substring 11, remember whether the last bit is 1 while the input remains valid. Start with “no trailing 1.” A second consecutive 1 sends the run to a rejecting state that loops on both symbols. A sink state has all transitions back to itself. Here the sink rejects because an occurrence of 11 survives every extension.
For exactly three symbols, track lengths 0, 1, 2, 3 and “4 or more.” On either bit, advance the count up to the last state. Accept only the state for length 3. From length 4 onward, the rejecting sink keeps the decision fixed.
Sipser, Introduction to the Theory of Computation, §1.1.
3Track a remainder
A remainder modulo m is the number left after dividing by m, between 0 and m−1. Appending a bit b to a binary prefix of value v changes the value to 2v+b. The same update can be made from the old remainder r, using (2r+b) mod m.
For 10101 modulo five, start at 0 and read 1 → 0 → 1 → 0 → 1. The remainders after these steps are 1, 2, 0, 0, 1. Thus the value 21 is not divisible by five. A DFA would use states 0 through 4 and accept only 0. Giving ε value zero accepts it, so add a separate nonaccepting start if the input must be a nonempty numeral.
On the unary alphabet {0}, tracking length modulo 14 uses the update (r+1) mod 14. Accept remainders 0, 2, 4, 6, 7, 8, 10 and 12 to test whether the length is divisible by 2 or 7.
4Compare the sets of accepted strings
A proper subset A ⊊ B means every member of A belongs to B, and at least one member of B lies outside A. The explicit extra string is a witness that the inclusion is strict.
From either start, any accepted nonempty string must travel along the 1-transitions and take the accepting 0-transition last. A₂ requires two initial 1s and A₁ requires one. Hence every word accepted by A₂ is accepted by A₁. The string 10 reaches q₃ in A₁ and the sink q₃ in A₂. Therefore L(A₂) ⊊ L(A₁).
A witness such as 10 establishes a difference in one direction. To prove proper inclusion, also show that every accepted string on the smaller side belongs to the larger side.
A product automaton runs two DFAs on the same input. Its state (p,q) records the current states, and each bit updates both coordinates. Starting at the pair of start states, enumerate reachable pairs. A reachable pair with first coordinate accepting and second rejecting supplies a witness against L(A) ⊆ L(B). If no pair of that kind is reachable, inclusion holds. Apply the same test with the machines reversed to distinguish equality, strict inclusion and incomparability.
For 110, the pair begins at (q₀,q₀). The first 1 gives (q₁,q₁). The next 1 gives (q₁,q₂). The final 0 gives (q₃,q₄), an accepting state in both machines. This input does not separate them.
For even zeros and odd ones, store the pair of parities starting at (E,E). A 0 flips the first coordinate, and a 1 flips the second. Only (E,O) accepts. For 001 the trace is (E,E) → (O,E) → (E,E) → (E,O).
5Recap
- Choose how each state describes the prefix.
- For binary value modulo m, update (2r+b) mod m.
- A reachable product state can reveal a counterexample to inclusion.
6Check yourself
7Cheat card
- Design
- Name each state, verify the start, update the meaning on every symbol, then mark accepting states.
- Binary value
- Next remainder = (2r+b) mod m.
- Inclusion
- Search reachable pairs for first accepts and second rejects.
- Memory hook
- Give each state a sentence you can still say after following each arrow.