Lesson 4 introduces the first machine model. It covers state diagrams and tracing, the determinism requirement, the formal five-tuple, and transition tables, then defines the extended transition function by recursion and uses it to define acceptance, the language of a machine, and a regular language. From there it gives a design recipe built on asking what has to be remembered, and covers dead states, counting modulo a fixed number, the product construction for union and intersection, complement by swapping the accepting set, and correctness proofs by invariant.
Subject: Theory of Computation · 115 slides · symbolic lesson
Open the interactive version of this deck · Homework for this lesson
Title
Theory of Computation · Lesson 4
The simplest machine worth studying: finitely many states, one arrow per symbol, and no memory beyond where you are standing.
Objectives
Lessons 1 to 3 built the vocabulary. This lesson builds the first machine, and with it the first class of languages. By the end you can:
Warm-up
Discussion prompt
Before we open Deterministic Finite Automata: without looking back, what was the main idea of Strings & Languages, and what could you do by the end of it that you could not do before?
Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.
Answer:
Lesson 3 of the math toolkit and the gateway to automata: alphabets and strings, length and the empty string, concatenation and its algebra, substrings/prefixes/suffixes, string exponentiation and reversal, the set of all strings, languages as sets of strings, language operations including Kleene star, and the counting results that show strings are countable but languages are not. Targets the empty-string-vs-empty-set confusion, substring-vs-subsequence, the reversal-of-concatenation order, and star-vs-plus.
Section
Section 1
Concept
A finite automaton is the smallest interesting model of computation. It reads an input string once, left to right, and it never goes back.
Its entire memory is which state it is currently in. There is no tape to write on, no counter, no stack — just a marker sitting on one circle of a diagram.
\[ \text{memory} \;=\; \text{one element of a finite set } Q \]
finite automaton — A machine with finitely many states that reads its input once, changing state on each symbol, and answers yes or no when the input runs out.
Counterexample
Discussion prompt
A finite automaton is the smallest interesting model of computation. It reads an input string once, left to right, and it never goes back.
That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.
Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.
Answer:
Its entire memory is which state it is currently in. There is no tape to write on, no counter, no stack — just a marker sitting on one circle of a diagram.
Intuition
The restriction sounds mild until you try to use it. If a machine has ten states, then after reading a million symbols it is in one of ten situations — and it cannot tell which million-symbol string got it there.
So anything a machine needs to remember must fit into a bounded number of distinctions. It can remember 'the last symbol was a 1'. It cannot remember 'I have seen 4,192 more zeros than ones', because that quantity has no bound.
Picture it
Figure (svg): Automaton with states q0, q1
Discussion prompt
Read the picture before the words. What is this showing, and what is the one thing it is built to make obvious? Commit to an answer, then read on.
Hint: Name the parts, then say what changes between them — and if nothing changes, say what is being held still.
Answer:
A machine is drawn as a directed graph. Four conventions carry all the information, and every diagram in this course obeys them.
Concept
A machine is drawn as a directed graph. Four conventions carry all the information, and every diagram in this course obeys them.
Figure (svg): Automaton with states q0, q1
Analogy
Discussion prompt
Explain The state diagram: circles and arrows by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.
Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.
Answer:
A machine is drawn as a directed graph. Four conventions carry all the information, and every diagram in this course obeys them.
Concept
To run a machine on a string: put a marker on the start state, then for each symbol in turn, follow the arrow with that label.
When the input runs out, look at where the marker stopped. If it is on a double circle the machine accepts; otherwise it rejects. The walk is the whole computation.
\[ \text{accept} \iff \text{final resting state} \in F \]
Notice what is not part of the procedure. There is no backtracking, no lookahead, and no second pass. One symbol, one arrow, forwards only.
Explain it
Discussion prompt
Explain Reading a string is walking the diagram to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.
Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.
Answer:
To run a machine on a string: put a marker on the start state, then for each symbol in turn, follow the arrow with that label.
Picture it
Figure (svg): Automaton with states q0, q1
Discussion prompt
Read the picture before the words. What is this showing, and what is the one thing it is built to make obvious? Commit to an answer, then read on.
Hint: Name the parts, then say what changes between them — and if nothing changes, say what is being held still.
Answer:
Does the machine above accept the string 1101? Walk it symbol by symbol.
Worked example
Does the machine above accept the string 1101? Walk it symbol by symbol.
Figure (svg): Automaton with states q0, q1
Start on the start state and read the first symbol, 1
Why: The arrow labelled 1 out of the start state leads to the double circle. Move there. Three symbols remain.
\[ \delta(q_0, 1) = q_1 \qquad \text{left to read: } 101 \]
Read the second symbol, 1
Why: From the double circle the arrow labelled 1 is a self-loop, so the marker stays put. Two symbols remain.
\[ \delta(q_1, 1) = q_1 \qquad \text{left to read: } 01 \]
Read the third symbol, 0
Why: From the double circle the arrow labelled 0 leads back to the start state. One symbol remains.
\[ \delta(q_1, 0) = q_0 \qquad \text{left to read: } 1 \]
Read the last symbol, 1
Why: From the start state the arrow labelled 1 leads to the double circle. The input is now empty, so the walk ends here.
\[ \delta(q_0, 1) = q_1 \qquad \text{left to read: } \varepsilon \]
Verify by re-walking the whole path, then decide
Why: The marker finished on a double circle, so the machine accepts. Reading the four arrows back in order confirms the path: to the accepting state, self-loop, back to the start, and to the accepting state again. Four symbols, four arrows, ending accepting.
\[ q_0 \xrightarrow{1} q_1 \xrightarrow{1} q_1 \xrightarrow{0} q_0 \xrightarrow{1} q_1 \in F \ \checkmark \]
Notation
Annotate
From Trace a string through a two-state machine — read this one piece at a time. What is each part doing?
On: \( \delta(q_0, 1) = q_1 \qquad \text{left to read: } 101 \)
Ranking
Put in order
These are the steps of How to trace a string through a machine, scrambled. Put them back in order before the next slide shows you.
Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.
Pattern
Tracing is mechanical. Doing it the same way every time is what stops the careless errors.
Writing the state under each symbol turns the trace into a table you can check afterwards, which is far more reliable than following arrows in your head.
Elimination
Eliminate the wrong options
Which of these strings does the machine reject?
3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.
Survives elimination: A
Why: The machine accepts exactly the strings whose last symbol is 1, because a 1 always moves to the accepting state and a 0 always leaves it. The string 110 ends in 0, so the walk finishes on the non-accepting state.
Check
Use the two-state machine above: 0 keeps you on the left, 1 sends you to the double circle.
Check your understanding
Which of these strings does the machine reject?
Answer: A
Why: The machine accepts exactly the strings whose last symbol is 1, because a 1 always moves to the accepting state and a 0 always leaves it. The string 110 ends in 0, so the walk finishes on the non-accepting state.
Intuition
Here is the single most useful sentence about these machines: the state is everything the machine knows.
Two different strings that drive the machine into the same state are, from that moment on, completely indistinguishable to it. Whatever happens next depends only on the state and the symbols still to come.
\[ \hat{\delta}(q_0,u) = \hat{\delta}(q_0,v) \;\Longrightarrow\; \forall z: \hat{\delta}(q_0,uz) = \hat{\delta}(q_0,vz) \]
That is why designing a machine always reduces to one question: which distinctions between prefixes actually matter? Everything else can be collapsed.
Concept
The D in DFA is a hard requirement. From every state, for every symbol of the alphabet, there must be exactly one outgoing arrow carrying that label — no more and no fewer.
\[ \text{for every } q \in Q \text{ and every } a \in \Sigma: \quad \text{exactly one arrow } q \xrightarrow{\,a\,} p \]
Two consequences follow, and both matter.
Together these say that on a given input the machine has exactly one possible run. That is what makes its answer well defined — and it is exactly what Lesson 5 gives up.
Anomaly
Predict first
A student writes this, and it looks reasonable:
Does the machine that accepts strings ending in 1 accept the string 110?
It is wrong. Say what breaks — and say it before you turn the page.
Correct: Reading the first 1 lands the marker on the accepting state.
Does the machine that accepts strings ending in 1 accept the string 110?
Why: Reading the first 1 lands the marker on the accepting state. The run has reached a double circle, so mark the string accepted.
Trap
Does the machine that accepts strings ending in 1 accept the string 110?
Trace, and watch for the double circle
Why: Reading the first 1 lands the marker on the accepting state. The run has reached a double circle, so mark the string accepted.
\[ q_0 \xrightarrow{1} q_1 \xrightarrow{1} q_1 \xrightarrow{0} q_0 \]
Verdict: accept — the run visited the double circle along the way.
Does the machine that accepts strings ending in 1 accept the string 110?
Trace to the very end, then look exactly once
Why: Only the state reached after the LAST symbol decides anything. This run ends back on the start state, which is not a double circle. Everything it visited on the way is irrelevant.
\[ \hat{\delta}(q_0, 110) = q_0 \notin F \]
Verdict: reject — acceptance is a property of the final state alone.
Translation
\( \hat{\delta}(q_0, 110) = q_0 \notin F \)
Draw it
Translate both ways. First write the expression above as a sentence with no symbols in it at all. Then cover it, and write your sentence back as notation. If the two versions disagree, the disagreement is the thing to fix.
Concept
A double circle is not a finish line. The machine keeps reading whether or not it is standing on one.
Reaching an accepting state means only this: if the input happened to end right here, the answer would be yes. The machine may leave it on the very next symbol, and often does.
| Prefix read | State | Would we accept if it ended now? |
|---|---|---|
| (nothing) | start | no |
| 1 | accepting | yes |
| 11 | accepting | yes |
| 110 | start | no |
| 1101 | accepting | yes |
Reading that column downward is a good habit: it shows the machine answering the question afresh after every symbol.
Pattern
Step through it
Step through Accepting states answer the question, they do not stop the… one row at a time. What is driving the change, and what would the row after the last one be?
Section
Section 2
Concept
The picture is convenient but imprecise. The formal object is a tuple of five components, and every diagram is just a drawing of one.
\[ M = (Q, \Sigma, \delta, q_0, F) \]
| Component | What it is | In the picture |
|---|---|---|
| Q | a finite set of states | the circles |
| the alphabet | a finite set of symbols | the arrow labels |
| the transition function | a total function on state-symbol pairs | the arrows |
| the start state | one element of Q | the incoming stub |
| F | a subset of Q | the double circles |
Note the asymmetry that trips people up: the start state is a single state, while the accepting set is a set of states, possibly empty and possibly all of Q.
Comparison
Comparison matrix
From A machine is a five-tuple: refill the In the picture column from what you know. The rest of the table is as it appeared.
| Component | What it is | In the picture |
|---|---|---|
| Q | a finite set of states | the circles |
| the alphabet | a finite set of symbols | the arrow labels |
| the transition function | a total function on state-symbol pairs | the arrows |
| the start state | one element of Q | the incoming stub |
| F | a subset of Q | the double circles |
Concept
The state set and the alphabet are both required to be finite. Neither restriction is decorative.
\[ |Q| < \infty, \qquad |\Sigma| < \infty \]
A finite state set is the entire subject of the lesson — it is what makes the machine weak enough to analyse and strong enough to be interesting.
A finite alphabet keeps the transition function finite too: there are exactly as many arrows as there are state-and-symbol pairs, so the whole machine can be written down.
\[ \text{number of arrows} = |Q| \cdot |\Sigma| \]
Concept
The transition function takes a state and a symbol and returns a state.
\[ \delta : Q \times \Sigma \to Q \]
The word function already encodes both halves of determinism, which is why they are never stated separately.
So saying the transition function is total, with domain every state-and-symbol pair, is the formal way to say what the picture said with 'exactly one arrow per symbol'. Each arrow in the diagram is one pair-to-value assignment.
\[ \delta(q_0, 0) = q_0 \quad\Longleftrightarrow\quad \text{the arrow } q_0 \xrightarrow{\,0\,} q_0 \]
Concept
There is exactly one start state — a single element of the state set, not a set of states. Every computation, on every input, begins there.
The accepting set may be any subset at all, including the two extremes. Both extremes are legal machines and both are occasionally useful.
| Accepting set | Language recognized |
|---|---|
| empty | no strings at all |
| all of Q | every string over the alphabet |
| contains the start state | at least the empty string |
That last row is worth remembering. The empty string is accepted precisely when the start state is itself accepting, because no arrow is ever followed.
\[ \varepsilon \in L(M) \iff q_0 \in F \]
Trade off
Comparison matrix
From Where you begin and what counts as yes: every row here is a choice with a cost. Fill the Language recognized column, then say which row you would actually pick and what you give up for it.
| Accepting set | Language recognized |
|---|---|
| empty | no strings at all |
| all of Q | every string over the alphabet |
| contains the start state | at least the empty string |
Picture it
Figure (svg): Automaton with states q0, q1
Discussion prompt
Read the picture before the words. What is this showing, and what is the one thing it is built to make obvious? Commit to an answer, then read on.
Hint: Name the parts, then say what changes between them — and if nothing changes, say what is being held still.
Answer:
Convert the two-state machine into its formal tuple, one component at a time.
Worked example
Convert the two-state machine into its formal tuple, one component at a time.
Figure (svg): Automaton with states q0, q1
Read off the state set and the alphabet
Why: Two circles give two states. The arrow labels use only two distinct symbols, so the alphabet has two members.
\[ Q = \{q_0, q_1\}, \quad \Sigma = \{0,1\} \]
Read off the start state and the accepting set
Why: The incoming stub points at the left circle. Exactly one circle is drawn doubled, so the accepting set is a one-element set — not a bare state.
\[ q_0 \text{ is the start}, \qquad F = \{q_1\} \]
Read off every arrow as one value of the transition function
Why: There must be one entry for each state-and-symbol pair, so four entries in total. Any missing entry would mean the diagram is not a DFA at all.
\[ \delta(q_0,0)=q_0, \; \delta(q_0,1)=q_1, \; \delta(q_1,0)=q_0, \; \delta(q_1,1)=q_1 \]
Assemble the tuple
Why: Write the five components in the fixed order. The tuple now carries exactly the information the picture did, with nothing left implicit.
\[ M = (\{q_0,q_1\}, \{0,1\}, \delta, q_0, \{q_1\}) \]
Verify the count of arrows against the size rule
Why: Two states times two symbols predicts four arrows, and four were listed. Every pair appears exactly once, so the transition function really is total and single-valued — the tuple describes a legal DFA.
\[ |Q| \cdot |\Sigma| = 2 \cdot 2 = 4 \text{ arrows} \ \checkmark \]
Reverse engineer
Discussion prompt
Work backwards. The example finished here:
Verify the count of arrows against the size rule
What was it asked to do, and what must it have been given? Reconstruct the problem from its answer.
Hint: Every quantity in the result had to enter somewhere. Account for each one.
Answer:
Convert the two-state machine into its formal tuple, one component at a time.
Concept
The transition function is usually written as a table: one row per state, one column per symbol. It is the same information as the arrows, arranged for lookup.
| state | 0 | 1 |
|---|---|---|
| -> q0 | q0 | q1 |
| * q1 | q0 | q1 |
Two marks carry the rest of the tuple: an arrow marks the start row and a star marks the accepting rows. With those, the table alone determines the machine.
The table also makes one property visible at a glance: every cell must be filled with exactly one state. A blank cell or a cell holding two states means the object is not a DFA.
Comparison
Comparison matrix
From The transition table: refill the 1 column from what you know. The rest of the table is as it appeared.
| state | 0 | 1 |
|---|---|---|
| -> q0 | q0 | q1 |
| * q1 | q0 | q1 |
Ranking
Put in order
Put the moves of Turn a transition table back into a diagram into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Three rows give three circles. Mark the row with the arrow as the start, and double the starred row.
Worked example
Reconstruct the machine from this table alone.
| state | a | b |
|---|---|---|
| -> s0 | s1 | s0 |
| s1 | s1 | s2 |
| * s2 | s1 | s0 |
Draw one circle per row
Why: Three rows give three circles. Mark the row with the arrow as the start, and double the starred row.
\[ Q = \{s_0, s_1, s_2\}, \qquad F = \{s_2\} \]
Draw one arrow per cell
Why: Each cell becomes an arrow from its row's state to the state named inside it, labelled with the column's symbol. Cells naming their own row become self-loops.
\[ 3 \text{ rows} \times 2 \text{ columns} = 6 \text{ arrows} \]
Trace a string to sanity-check the drawing
Why: Run abab: from the start, a moves to the middle state, b moves to the accepting state, a returns to the middle, and b reaches the accepting state again.
\[ \hat{\delta}(s_0, abab) = s_2 \in F \]
Read the language off the structure
Why: The accepting state is reached only by a b taken from the middle state, and the middle state is reached only by an a. So a string is accepted exactly when it ends with the block ab.
Verify by counting arrows and testing the boundary
Why: Six arrows were drawn, matching three rows times two columns, so no cell was skipped. The empty string leaves the marker on the start state, which is not accepting — correct, since the empty string does not end in ab.
\[ 6 \text{ arrows} \quad \text{and} \quad \varepsilon \notin L(M) \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Turn a transition table back into a diagram", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: Six arrows were drawn, matching three rows times two columns, so no cell was skipped. The empty string leaves the marker on the start state, which is not accepting — correct, since the empty string does not end in ab.
Intuition
If you were to implement one of these machines, you would not draw anything. You would store the table as a two-dimensional array and write a three-line loop.
Start at the start state, index the array once per symbol, and test membership in the accepting set at the end. The running time is one array lookup per input symbol, and the memory used does not grow with the input at all.
That is the practical content of 'finite memory': constant space, linear time, no allocation. It is why this model still describes real lexers and pattern matchers.
\[ \text{time} = O(|w|), \qquad \text{space} = O(1) \]
Prediction
Predict first
Which situation means the object being described is NOT a DFA?
Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.
Correct: One state has no outgoing arrow labelled 0
Why: The transition function must be total: every state needs exactly one arrow for every symbol of the alphabet. A missing arrow means the machine could jam partway through an input, which the definition forbids.
Check
Consider a machine with three states over the two-symbol alphabet of zeros and ones.
Check your understanding
Which situation means the object being described is NOT a DFA?
Answer: A
Why: The transition function must be total: every state needs exactly one arrow for every symbol of the alphabet. A missing arrow means the machine could jam partway through an input, which the definition forbids.
Section
Section 3
Concept
The transition function consumes a single symbol. To talk about acceptance we need a function that consumes a whole string in one go.
Call it the extended transition function. It takes a state and a string, and returns the state the machine ends up in after reading that entire string.
\[ \hat{\delta} : Q \times \Sigma^{*} \to Q \]
The hat is not decoration. The two functions have different domains, and confusing them is the source of most notation errors in this subject.
Concept
The definition has one base case and one recursive case, mirroring how strings themselves were built in Lesson 3.
\[ \hat{\delta}(q, \varepsilon) = q \]
Reading nothing moves nowhere. That is the base case, and it is exactly why the empty string is accepted precisely when the start state is accepting.
\[ \hat{\delta}(q, wa) = \delta\big(\hat{\delta}(q, w),\, a\big) \]
The recursive case says: to read a string ending in the symbol a, first read everything before it, then take one ordinary step on a. The recursion peels symbols off the right.
A useful consequence falls straight out: on a one-symbol string the two functions agree, so the hat is a genuine extension and not a different operation.
\[ \hat{\delta}(q, a) = \delta(\hat{\delta}(q,\varepsilon), a) = \delta(q,a) \]
Step zero
Discussion prompt
Compute the extended function by unwinding the recursion — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.
Hint: It starts with: Apply the recursive case to peel off the last symbol
Answer:
Worked example
Use the two-state machine and compute where the string 110 finishes, working strictly from the definition rather than from the picture.
\[ \text{Compute } \hat{\delta}(q_0, 110) \]
Apply the recursive case to peel off the last symbol
Why: The string ends in 0, so the answer is one ordinary step on 0 taken from wherever the prefix 11 lands.
\[ \hat{\delta}(q_0, 110) = \delta\big(\hat{\delta}(q_0, 11),\, 0\big) \]
Peel again
Why: The same rule applies to the prefix. Now everything hinges on where the shorter prefix 1 lands.
\[ \hat{\delta}(q_0, 11) = \delta\big(\hat{\delta}(q_0, 1),\, 1\big) \]
Reach a case you can evaluate outright
Why: On a single symbol the extended function collapses to the ordinary one, which the table answers directly.
\[ \hat{\delta}(q_0, 1) = \delta(q_0, 1) = q_1 \]
Unwind back up
Why: Substitute that value into the line above it, then substitute the result into the line above that.
\[ \hat{\delta}(q_0,11) = \delta(q_1,1) = q_1, \qquad \hat{\delta}(q_0,110) = \delta(q_1,0) = q_0 \]
Verify the answer against a direct walk of the diagram
Why: Walking 1, then 1, then 0 through the picture gives accepting, accepting, start — finishing on the start state, which is not accepting. The recursion and the picture agree, and the string is rejected.
\[ \hat{\delta}(q_0,110) = q_0 \notin F \;\Rightarrow\; \text{reject} \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Compute the extended function by unwinding the recursion", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: Walking 1, then 1, then 0 through the picture gives accepting, accepting, start — finishing on the start state, which is not accepting. The recursion and the picture agree, and the string is rejected.
Concept
With the extended function in hand, acceptance takes one line and leaves nothing to interpretation.
\[ M \text{ accepts } w \iff \hat{\delta}(q_0, w) \in F \]
Every informal phrase used earlier now has a formal counterpart: 'start at the start state' is the first argument, 'read the whole string' is the extended function, and 'land on a double circle' is membership in the accepting set.
Note that this definition mentions only the final state. The trap from Section 1 is not a matter of taste — it contradicts the definition.
Concept
Collect every accepted string and you get a language. It is written with an L and is the machine's whole observable behaviour.
\[ L(M) = \{\, w \in \Sigma^{*} \;:\; \hat{\delta}(q_0, w) \in F \,\} \]
Two points are worth stating explicitly, because both come up constantly.
So 'the language of this machine' is a well-defined phrase, while 'the machine for this language' is not.
Concept
This is the definition the rest of the course is built on, and it is deliberately modest.
regular language — A language recognized by some deterministic finite automaton.
\[ L \text{ regular} \iff \exists\, M \text{ (a DFA)} \; . \; L(M) = L \]
Read the quantifier carefully. To prove a language regular you must exhibit one machine. To prove it not regular you must rule out every machine — a far harder job, which is what Lessons 10 and 11 are for.
Picture it
Figure (svg): Automaton with states p0, p1, p2
Discussion prompt
Read the picture before the words. What is this showing, and what is the one thing it is built to make obvious? Commit to an answer, then read on.
Hint: Name the parts, then say what changes between them — and if nothing changes, say what is being held still.
Answer:
Given this machine, describe its language in words and support the description.
Worked example
Given this machine, describe its language in words and support the description.
Figure (svg): Automaton with states p0, p1, p2
Ask what each state means
Why: Name each state by the property of the prefix read so far. The start state means no useful progress; the middle means the last symbol was a 0; the accepting state means the last two were 0 then 1.
Check the naming is consistent with every arrow
Why: From 'last symbol was 0', reading another 0 keeps that description true, and reading a 1 completes the pattern. Every arrow preserves the meaning assigned to its destination.
Read the language off the accepting state's meaning
Why: The only accepting state means exactly 'the last two symbols were 0 then 1', so those are precisely the accepted strings.
\[ L(M) = \{\, w \in \{0,1\}^{*} : w \text{ ends in } 01 \,\} \]
Spot-check two strings
Why: The string 101 ends in 01 and is accepted; the string 010 does not and is rejected.
Verify the description on the boundary string
Why: The empty string does not end in anything, so the description says reject. Running it follows no arrow at all, leaving the marker on the start state, which is not accepting. Description and machine agree on the hardest case.
\[ \hat{\delta}(p_0, \varepsilon) = p_0 \notin F \ \checkmark \]
Notation
Annotate
From Describe the language of a machine, and justify it — read this one piece at a time. What is each part doing?
On: \( \hat{\delta}(p_0, \varepsilon) = p_0 \notin F \ \checkmark \)
Intuition
The state-naming trick in that example was not luck. It is the whole theory in miniature.
Group the prefixes by which state they reach. Two prefixes in the same group are interchangeable: appending any string to either gives the same verdict, because the machine cannot tell them apart.
So the states of a machine are the distinctions it makes among prefixes — no more and no fewer. A machine with three states makes exactly three distinctions, and a language needing four cannot be recognized by it.
\[ \text{states} \;\longleftrightarrow\; \text{classes of prefixes with a common future} \]
Pattern
Reverse-engineering a diagram follows a fixed order. Guessing from a few traces is unreliable.
Step two is the one that turns a guess into a proof, because a set of names surviving it is exactly an invariant — which Section 5 makes formal.
Commit first
Predict first
For a DFA M, when is the empty string in L(M)?
Commit to an answer, then rate it — certain, fairly sure, or guessing — and write the rating down before you turn the page.
Correct: Exactly when the start state is an accepting state
Why: The extended transition function on the empty string returns the state it started from, so the final state is the start state itself. Acceptance then reduces to asking whether that state belongs to the accepting set.
The rating matters as much as the answer: confident-and-wrong is the combination that survives revision, because nothing about it feels like it needs revisiting.
Check
Work from the definitions rather than from a picture.
Check your understanding
For a DFA M, when is the empty string in L(M)?
Answer: A
Why: The extended transition function on the empty string returns the state it started from, so the final state is the start state itself. Acceptance then reduces to asking whether that state belongs to the accepting set.
Section
Section 4
Constraint
Discussion prompt
Run The design recipe with this step confiscated:
Decide which answers mean 'yes, if the input stopped now' — those states are accepting.
Is it still possible? If it is, say what takes its place and what it costs you. If it is not, say exactly what that step was providing that nothing else does.
Hint: A step you can drop for free was never load-bearing. If you cannot drop it, name the thing that goes wrong the moment it is gone.
Answer:
Pattern
Designing a machine is the reverse of the previous section, and it runs on one question.
If step one has infinitely many answers, no machine exists and no amount of cleverness will produce one. That is not a failure of the method; it is the method telling you something true.
\[ \textit{What must I remember about the prefix read so far?} \]
Edge cases
Discussion prompt
The design recipe works on the cases you have just seen. Push it to the edge: what is the most degenerate input it still handles — empty, zero, one item, everything equal — and what is the first case where it stops being true? Name the case, not just "it breaks".
Hint: Try the smallest legal input, then the largest, then the one where two things collide. Methods are specified at their edges; the middle takes care of itself.
Answer:
Designing a machine is the reverse of the previous section, and it runs on one question.
Concept
The recipe is easy to state and hard to apply, because the instinct is to remember too much.
A useful reframing: your job is to throw away as much of the prefix as you possibly can. Every distinction you keep costs a state, and keeping an unbounded number of them means there is no machine.
| Requirement | What must be remembered | States needed |
|---|---|---|
| ends in 01 | how much of 01 is complete | three |
| contains 001 | how much of 001 is complete, or done | four |
| even number of ones | the count modulo two | two |
| equally many zeros and ones | the running difference | unbounded, so none |
Trade off
Comparison matrix
From Design is about forgetting, not remembering: every row here is a choice with a cost. Fill the What must be remembered column, then say which row you would actually pick and what you give up for it.
| Requirement | What must be remembered | States needed |
|---|---|---|
| ends in 01 | how much of 01 is complete | three |
| contains 001 | how much of 001 is complete, or done | four |
| even number of ones | the count modulo two | two |
| equally many zeros and ones | the running difference | unbounded, so none |
Estimation
Predict first
Build a machine over the alphabet of zeros and ones accepting exactly the strings whose last two symbols are 0 then 1.
Commit before you compute: what does Design: strings that end in 01 come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.
Correct: Verify on four strings including the boundary
Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. The strings 01 and 1101 end in 01 and are accepted.
Worked example
Build a machine over the alphabet of zeros and ones accepting exactly the strings whose last two symbols are 0 then 1.
Answer the design question
Why: To know whether to accept, it is enough to know how much of the pattern 01 currently sits at the end. There are three answers: nothing, a trailing 0, or a completed 01.
Make one state per answer and mark the accepting one
Why: Three states. The one meaning 'the pattern just completed' is the only accepting state, since that is precisely the condition.
\[ Q = \{\text{none}, \text{saw }0, \text{saw }01\}, \quad F = \{\text{saw }01\} \]
Fill in the arrows from the meanings
Why: Reading a 0 always leaves a trailing 0, from any state at all. Reading a 1 completes the pattern only when a 0 was pending, and otherwise leaves nothing pending.
Notice the arrow people get wrong
Why: From the accepting state, reading a 0 must go back to 'saw 0', not to 'none'. The 0 just read is itself a fresh start of the pattern, and forgetting that loses strings like 0101.
Verify on four strings including the boundary
Why: The strings 01 and 1101 end in 01 and are accepted. The string 010 ends in 10 and is rejected, and the empty string follows no arrow and is rejected too. All four verdicts match the specification, including the case the previous step warned about.
\[ 01,\ 1101,\ 0101 \in L \qquad 010,\ \varepsilon \notin L \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Design: strings that end in 01", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: The strings 01 and 1101 end in 01 and are accepted. The string 010 ends in 10 and is rejected, and the empty string follows no arrow and is rejected too. All four verdicts match the specification, including the case the previous step warned about.
Intuition
That subtle arrow is worth dwelling on, because the same mistake reappears in every substring-matching design.
After matching a pattern, the symbols you just consumed may themselves begin the next match. A machine that resets to the very beginning throws away real progress, and the strings it then rejects are exactly the ones with overlapping occurrences.
The reliable habit: for each state and symbol, ask what the longest suffix of the prefix-so-far is that could still grow into the pattern. That question always has a unique answer, and it always gives the correct arrow.
\[ \text{next state} = \text{longest suffix that is a prefix of the pattern} \]
Step zero
Discussion prompt
Design: strings containing 001 somewhere — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.
Hint: It starts with: Answer the design question
Answer:
Worked example
Now the pattern may appear anywhere, and once it has appeared nothing can undo it.
Answer the design question
Why: Track how much of the block currently sits at the end, plus one extra answer: the block has already been found. Four answers in all.
\[ Q = \{\text{none}, 0, 00, \text{found}\}, \quad F = \{\text{found}\} \]
Make the found state absorbing
Why: Once the block has appeared, the string qualifies no matter what follows. So both arrows out of that state loop back to it.
Fill in the remaining arrows by the longest-suffix rule
Why: From 'saw 0', another 0 gives 'saw 00'; from 'saw 00', another 0 keeps 'saw 00', since the newest two zeros still form the best partial match. A 1 from 'saw 00' completes the block.
Check the arrow that is easy to get wrong
Why: From 'saw 00', reading a 0 must stay at 'saw 00' rather than falling back. The string 0001 depends on it, and a machine that resets would reject that string wrongly.
Verify on a member, an overlapping member, and a non-member
Why: The strings 001 and 0001 both contain the block and are accepted. The string 0101 contains no 001 anywhere, and tracing it never reaches the absorbing state, so it is correctly rejected.
\[ 001,\ 0001 \in L \qquad 0101,\ \varepsilon \notin L \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Design: strings containing 001 somewhere", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: From 'saw 00', reading a 0 must stay at 'saw 00' rather than falling back. The string 0001 depends on it, and a machine that resets would reject that string wrongly.
Concept
Sometimes a prefix rules out acceptance forever. The honest way to record that is a state you can never leave.
A dead state is non-accepting and loops to itself on every symbol. It exists so the transition function stays total, which the definition demands.
\[ \delta(d, a) = d \; \text{for every } a \in \Sigma, \qquad d \notin F \]
Dead states are usually omitted from diagrams to reduce clutter, with the convention that a missing arrow leads to one. That convention is fine in a picture and wrong in a tuple — the formal object must list every transition.
Ranking
Put in order
Put the moves of Design: exactly one 1 into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. How many ones have been seen: none, exactly one, or more than one.
Worked example
A counting condition where exceeding the count is fatal, which is what forces a dead state.
Answer the design question
Why: How many ones have been seen: none, exactly one, or more than one. The third answer can never be recovered from.
\[ Q = \{\text{zero ones}, \text{one one}, \text{too many}\}, \quad F = \{\text{one one}\} \]
Wire the zeros
Why: Zeros never change the count, so every state has a self-loop on 0. This is the step most often forgotten, and omitting it leaves the transition function partial.
Wire the ones
Why: A 1 advances the count by one: none becomes one, one becomes too many, and too many stays too many.
Identify the dead state
Why: 'Too many' is non-accepting and loops on both symbols, so it is a dead state. It is genuinely needed here — without it the machine would jam on a second 1.
Verify across all three counts
Why: The strings 1 and 001000 have exactly one 1 and are accepted. The empty string has none and is rejected, and 101 has two and lands in the dead state. All four agree with the specification.
\[ 1,\ 001000 \in L \qquad \varepsilon,\ 101 \notin L \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Design: exactly one 1", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: The strings 1 and 001000 have exactly one 1 and are accepted. The empty string has none and is rejected, and 101 has two and lands in the dead state. All four agree with the specification.
Concept
Counting conditions split cleanly into two kinds, and recognizing which kind you have saves a great deal of wasted effort.
A count that is compared against a fixed bound is fine: there are boundedly many answers, one per value up to the bound, plus one for 'past it'.
A count taken modulo a fixed number is also fine, and needs only as many states as there are remainders. But an unbounded count with no modulus needs infinitely many states, so no machine exists.
\[ \text{count} \in \{0,1,2,\dots\} \; \text{(infinite)} \qquad \text{count} \bmod k \in \{0,\dots,k-1\} \; \text{(finite)} \]
This single observation predicts almost every non-regularity result in Lesson 11 before any proof is written.
Step zero
Discussion prompt
Design: binary numbers divisible by three — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.
Hint: It starts with: Answer the design question
Answer:
Worked example
A modular condition on the value of the input, read as a binary numeral most significant bit first.
Answer the design question
Why: The remainder of the value so far, modulo three. Three answers, so three states, and the accepting one is remainder zero.
\[ L = \{\, w \in \{0,1\}^{*} : \mathrm{value}_2(w) \equiv 0 \pmod 3 \,\} \]
Find how the value changes when one bit arrives
Why: Appending a bit doubles the value and adds the bit. That is the standard place-value rule, and it is all the machine needs.
\[ \mathrm{value}(wb) = 2\cdot\mathrm{value}(w) + b \]
Reduce the rule modulo three
Why: Since doubling and adding commute with taking remainders, the new remainder depends only on the old remainder and the bit — never on the actual value. That is exactly why finite memory suffices.
\[ r \;\longmapsto\; (2r + b) \bmod 3 \]
Fill in the table from the rule
Why: From remainder 0, a 0 gives 0 and a 1 gives 1. From remainder 1, a 0 gives 2 and a 1 gives 0. From remainder 2, a 0 gives 1 and a 1 gives 2.
| remainder | 0 | 1 |
|---|---|---|
| * 0 | 0 | 1 |
| 1 | 2 | 0 |
| 2 | 1 | 2 |
Verify on two numerals with known values
Why: The numeral 110 has value six, which is divisible by three, and tracing it ends at remainder zero. The numeral 101 has value five, leaving remainder two, and tracing it agrees. Both match the arithmetic.
\[ \mathrm{value}_2(110) = 6 \equiv 0, \qquad \mathrm{value}_2(101) = 5 \equiv 2 \pmod 3 \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Design: binary numbers divisible by three", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: The numeral 110 has value six, which is divisible by three, and tracing it ends at remainder zero. The numeral 101 has value five, leaving remainder two, and tracing it agrees. Both match the arithmetic.
Prediction
Predict first
How many states does the smallest DFA need for the strings over a two-symbol alphabet whose length is divisible by four?
Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.
Correct: Four
Why: The only thing that matters is the length taken modulo four, which has exactly four possible values. One state per remainder suffices, with the remainder-zero state accepting, and no two of those states can be merged because each has a different future.
Check
Think about how many distinct situations the machine must tell apart.
Check your understanding
How many states does the smallest DFA need for the strings over a two-symbol alphabet whose length is divisible by four?
Answer: A
Why: The only thing that matters is the length taken modulo four, which has exactly four possible values. One state per remainder suffices, with the remainder-zero state accepting, and no two of those states can be merged because each has a different future.
Pattern
When a design stalls, it is nearly always the state set. Work through these in order.
Drawing before step four is what produces machines with missing arrows and duplicated states.
Section
Section 5
Concept
Given two machines, you can build a single machine that runs both of them simultaneously on the same input.
Its states are pairs, one component per machine, and each symbol updates both components together.
\[ Q = Q_1 \times Q_2, \qquad \delta\big((p,q), a\big) = \big(\delta_1(p,a),\, \delta_2(q,a)\big) \]
Both components advance in lockstep on the same input — the machine never chooses which one to run. The state count multiplies: the number of pairs is the product of the two state counts.
Choosing the accepting set then chooses the operation. Accept when either component accepts and you get union; accept when both do and you get intersection.
| Accepting pairs | Language obtained |
|---|---|
| either component accepting | the union |
| both components accepting | the intersection |
| the first but not the second | the difference |
Comparison
Comparison matrix
From The product construction: track two facts at once: refill the Language obtained column from what you know. The rest of the table is as it appeared.
| Accepting pairs | Language obtained |
|---|---|
| either component accepting | the union |
| both components accepting | the intersection |
| the first but not the second | the difference |
Hypothesis
Predict first
Design: an even number of a's and an even number of b's is about to be worked. State your hypothesis first: which rule or definition decides this one, and what is the first move it forces? Then watch whether the example agrees with you.
Correct: Build the two one-condition machines
Why: Each is a two-state parity machine: one tracks the count of a's modulo two, the other the count of b's. Each ignores the symbol it is not counting.
A hypothesis you wrote down is falsifiable; a vague sense of how it will go is not. If the example opens somewhere else, that gap is the thing worth chasing.
Worked example
Two independent parity conditions, which is exactly what the product construction is for.
Build the two one-condition machines
Why: Each is a two-state parity machine: one tracks the count of a's modulo two, the other the count of b's. Each ignores the symbol it is not counting.
Form the pairs
Why: Four pairs, one per combination of the two parities. Name them by the pair of answers rather than by a number, so the meaning stays visible.
\[ (\,\#_a \bmod 2, \#_b \bmod 2\,) \in \{E,O\} \times \{E,O\} \]
Wire each symbol to flip exactly one component
Why: Reading an a flips the first component and leaves the second alone; reading a b does the reverse. No arrow ever changes both.
Choose the accepting set
Why: Both conditions must hold, so exactly one pair is accepting: the one where both parities are even. That is intersection, not union.
\[ F = \{(E,E)\} \]
Verify on one accepted and two rejected strings
Why: The string abba has two a's and two b's, so it must be accepted, and it does end in the even-even corner. The string aab has an odd count of b's and ends in even-odd, and the string ab ends in odd-odd. Both are correctly rejected.
\[ abba: (E,E) \in F \qquad aab: (E,O) \notin F \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Design: an even number of a's and an even number of b's", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: The string abba has two a's and two b's, so it must be accepted, and it does end in the even-even corner. The string aab has an odd count of b's and ends in even-odd, and the string ab ends in odd-odd. Both are correctly rejected.
Intuition
A common first guess is that combining a two-state machine with a two-state machine needs four arrows and two states. It needs four states, and the reason is worth internalizing.
The machine must be able to answer both questions at every moment. Knowing only 'some condition holds' is not enough — it must know which combination holds, and there are as many combinations as there are pairs.
That multiplication is also the honest cost. Two machines of ten states each produce a hundred, and three produce a thousand, which is why the construction is a proof technique far more often than an implementation technique.
\[ |Q| = |Q_1| \cdot |Q_2| \]
Concept
Spot-checking strings builds confidence but proves nothing. A proof attaches a claim to every state and shows the arrows preserve it.
invariant — A property assigned to each state, such that after reading any string the machine is in the state whose property that string satisfies.
\[ \hat{\delta}(q_0, w) = q \iff I_q(w) \]
Proved by induction on the length of the input: the base case checks the empty string, and the step shows every arrow carries a true claim to another true claim. Then acceptance is immediate, since the accepting states are exactly those whose claims describe the language.
Matching
Match the pairs
Match each term to the definition this lesson gave it — not the one you would guess from the word.
Why: These are the working definitions of finite automaton, regular language, invariant as Deterministic Finite Automata uses them. Pairing them correctly is the test of whether you could state each one with the slide switched off.
Step zero
Discussion prompt
Prove the parity machine correct by induction — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.
Hint: It starts with: Check the base case
Answer:
Worked example
Take the two-state machine that accepts strings with an even number of ones, and prove it rather than test it.
\[ I_E(w): \#_1(w) \text{ is even} \qquad I_O(w): \#_1(w) \text{ is odd} \]
Check the base case
Why: On the empty string the machine has moved nowhere, so it sits in the even state. The empty string contains zero ones, and zero is even, so the claim attached to that state holds.
\[ \hat{\delta}(E,\varepsilon) = E \; \text{ and } \; \#_1(\varepsilon) = 0 \text{ even} \]
Set up the inductive step
Why: Assume the claim holds after reading some string, and read one more symbol. There are two symbols to consider, so two cases.
Handle the symbol that changes nothing
Why: Reading a 0 leaves the count of ones untouched, and the machine takes a self-loop. Both sides are unchanged, so the claim survives.
\[ \#_1(w0) = \#_1(w), \qquad \delta(q,0) = q \]
Handle the symbol that flips the parity
Why: Reading a 1 raises the count by one, flipping its parity, and the machine crosses to the other state. Both sides flip together, so the claim survives here too.
\[ \#_1(w1) = \#_1(w) + 1, \qquad \delta(E,1)=O, \; \delta(O,1)=E \]
Verify the invariant on a concrete string, then conclude
Why: The invariant holds for every input, so the accepted strings are exactly those with an even count. Testing 1011, which has three ones, the invariant predicts the odd state: tracing gives even, odd, odd, even, odd — ending odd, so it is rejected, exactly as predicted.
\[ \hat{\delta}(E, 1011) = O, \qquad \#_1(1011) = 3 \text{ (odd)} \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Prove the parity machine correct by induction", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: On the empty string the machine has moved nowhere, so it sits in the even state. The empty string contains zero ones, and zero is even, so the claim attached to that state holds.
Concept
Given a machine, build a second one by keeping every component unchanged and replacing the accepting set with its complement inside the state set.
\[ M' = (Q, \Sigma, \delta, q_0, Q \setminus F) \]
Why it works: on any input the two machines follow the identical path, since they share a transition function and a start state. They therefore finish in the same state, and exactly one of the two machines finds that state in its accepting set.
\[ L(M') = \overline{L(M)} = \Sigma^{*} \setminus L(M) \]
So the regular languages are closed under complement, with a construction that adds no states at all.
Explain it
Discussion prompt
Explain Complement: swap the accepting set to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.
Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.
Answer:
Given a machine, build a second one by keeping every component unchanged and replacing the accepting set with its complement inside the state set.
Ranking
Put in order
Put the moves of Complement a machine and read off the new language into the order they have to happen.
Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. Same two states, same four arrows, same start state.
Worked example
Take the two-state machine for strings ending in 1 and complement it.
Keep everything except the accepting set
Why: Same two states, same four arrows, same start state. Nothing about the paths changes.
Swap the accepting set
Why: The accepting set had one member, so its complement inside a two-state set has the other one.
\[ F' = \{q_0, q_1\} \setminus \{q_1\} = \{q_0\} \]
Describe the new language
Why: The new accepting state means 'the last symbol was not a 1', which covers strings ending in 0 — and also the empty string, which has no last symbol at all.
\[ L(M') = \{\varepsilon\} \cup \{\, w : w \text{ ends in } 0 \,\} \]
Note where the construction needed determinism
Why: The argument leaned on there being exactly one path per input. With several paths the same input could reach an accepting state along one and a non-accepting state along another, and swapping would not negate anything — a failure Lesson 5 examines in detail.
Verify on one string from each side
Why: The string 10 ends in 0, so the original rejects it and the complement must accept it. The string 11 ends in 1, so the original accepts and the complement must reject. Both strings switch sides, which is what complementing means.
\[ 10 \in L(M') \setminus L(M), \qquad 11 \in L(M) \setminus L(M') \ \checkmark \]
Picture it
Animation
Shows: Each line of the worked example "Complement a machine and read off the new language", appearing one at a time.
The same working the example does, in the order a tutor would write it.
Takeaway: The string 10 ends in 0, so the original rejects it and the complement must accept it. The string 11 ends in 1, so the original accepts and the complement must reject. Both strings switch sides, which is what complementing means.
Anomaly
Predict first
A student writes this, and it looks reasonable:
Build the machine for 'exactly one 1', and write down its transition table.
It is wrong. Say what breaks — and say it before you turn the page.
Correct: The design cared about counting ones, so record what a 1 does from each state and leave the rest, since zeros are uninteresting.
Build the machine for 'exactly one 1', and write down its transition table.
Why: The design cared about counting ones, so record what a 1 does from each state and leave the rest, since zeros are uninteresting.
Trap
Build the machine for 'exactly one 1', and write down its transition table.
List only the arrows the design needed
Why: The design cared about counting ones, so record what a 1 does from each state and leave the rest, since zeros are uninteresting.
| state | 0 | 1 |
|---|---|---|
| -> none | one | |
| * one | many | |
| many | many |
Run the string 001
Why: From the start state the first symbol is a 0, and the table has no entry. The machine jams before it has read anything meaningful.
\[ \delta(\text{none}, 0) = \text{?} \]
Build the machine for 'exactly one 1', and write down its transition table.
Fill every cell, including the boring ones
Why: The transition function is total by definition, so a cell for each state-and-symbol pair must be filled. Zeros never change the count, so each is a self-loop — boring, and mandatory.
| state | 0 | 1 |
|---|---|---|
| -> none | none | one |
| * one | one | many |
| many | many | many |
Run the string 001
Why: The two zeros are self-loops at the start state, then the 1 moves to the accepting state. The string is accepted, correctly, and the machine never jams on any input.
\[ \hat{\delta}(\text{none}, 001) = \text{one} \in F \ \checkmark \]
Pattern
Step through it
Step through Trap: leaving a transition out of the table one row at a time. What is driving the change, and what would the row after the last one be?
Intuition
Complement was easy because it needed no new states. Other operations are not so kind, and one of them is already out of reach.
Try to build a machine for the strings with equally many zeros and ones. The gap between the two counts is an integer with no bound, and every value of it must be tracked separately, since a prefix with a gap of three and one with a gap of four have different futures.
\[ L = \{\, w : \#_0(w) = \#_1(w) \,\} \quad \text{— no DFA exists} \]
Infinitely many distinctions, finitely many states. That is a genuine impossibility rather than a failure of imagination, and Lesson 10 supplies the tool that proves it.
Analogy
Discussion prompt
Explain The limitation you can already feel by analogy to something with no Theory of Computation in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.
Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.
Answer:
Complement was easy because it needed no new states. Other operations are not so kind, and one of them is already out of reach.
Elimination
Eliminate the wrong options
Which construction on deterministic finite automata leaves the number of states unchanged?
3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.
Survives elimination: A
Why: Complementing keeps the state set, the alphabet, the transition function and the start state, and changes only which states are marked accepting. Nothing is added, so the state count is identical.
Check
One of these constructions adds no states at all.
Check your understanding
Which construction on deterministic finite automata leaves the number of states unchanged?
Answer: A
Why: Complementing keeps the state set, the alphabet, the transition function and the start state, and changes only which states are marked accepting. Nothing is added, so the state count is identical.
Ranking
Put in order
These are the steps of Sanity checks for a machine you just designed, scrambled. Put them back in order before the next slide shows you.
Why: This is the order the recipe itself gives. Recalling the sequence without the slide in front of you is the difference between recognising the method and being able to run it — most of what goes wrong in practice is a step done out of turn.
Pattern
Run this list before trusting any machine you have drawn. It catches the overwhelming majority of design errors.
The last item is the one that upgrades a design from tested to proved, since a consistent set of names is exactly an invariant.
Real world
Discussion prompt
Outside this lesson: where does Deterministic Finite Automata actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of Sanity checks for a machine you just designed is doing the work in it.
Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.
Answer:
Lesson 4 introduces the first machine model. It covers state diagrams and tracing, the determinism requirement, the formal five-tuple, and transition tables, then defines the extended transition function by recursion and uses it to define acceptance, the language of a machine, and a regular language. From there it gives a design recipe built on asking what has to be remembered, and covers dead states, counting modulo a fixed number, the product construction for union and intersection, complement by swapping the accepting set, and correctness proofs by invariant.
Concept
The model is now completely specified, so its limits are worth stating plainly before the next lesson widens it.
Lesson 5 removes the third restriction on purpose and lets the machine take several arrows at once. The remarkable result is that this changes nothing about which languages can be recognized — but it changes a great deal about how easy they are to describe.
\[ \text{DFA} \;\equiv\; \text{NFA} \quad \text{(Lesson 6)} \]
Counterexample
Discussion prompt
The model is now completely specified, so its limits are worth stating plainly before the next lesson widens it.
That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.
Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.
Connect it up
Draw it
One page, no notation unless you need it: draw how these connect — A Machine With Finite Memory · The Formal Definition · Acceptance and the Language of a Machine · Designing a Machine · Combining and Complementing Machines. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.
Recap
You have the first machine model, its formal definition, and the beginnings of a theory of what it can and cannot do.
| Situation | Move |
|---|---|
| a diagram to understand | name every state by what it remembers |
| a language to recognize | list the answers to the design question |
| two conditions at once | the product construction |
| the opposite language | swap the accepting set, change nothing else |
| a design that will not close | check whether the count you need is unbounded |
Lesson 5 lets the machine take several paths at once, and Lesson 6 proves it gains no power by doing so.
Want this taught 1-on-1? Alexander tutors Theory of Computation — $55/session, free consultation.