Nondeterministic Finite Automata

Lesson 5 drops the determinism requirement and lets a machine take several arrows on one symbol, or none at all. It covers the active-set method of running such a machine, acceptance as an existential claim over paths, and the computation tree, then gives the five-tuple with its set-valued transition function, epsilon-arrows and epsilon-closure, and the extended transition function with closures. It closes with guess-and-verify design and the exponential saving in states it can produce, why swapping the accepting set fails to complement an NFA, and what nondeterminism is not.

Subject: Theory of Computation · 112 slides · symbolic lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. Nondeterministic Finite Automata

Title

Theory of Computation · Lesson 5

Let the machine take several arrows at once, or none at all. It becomes far easier to design — and, remarkably, no more powerful.

2. What you will be able to do

Objectives

Lesson 4 insisted on exactly one arrow per state per symbol. This lesson drops that rule and sees what happens. By the end you can:

  1. Run a machine that has several arrows on one symbol, by tracking the set of live states.
  2. State the acceptance rule precisely, and say why one dead branch proves nothing.
  1. Write the five-tuple when the transition function returns a set, and handle ε-arrows.
  2. Compute ε-closures and run a machine that has them.
  1. Design machines by the guess-and-verify method, often with far fewer states than a DFA needs.
  2. Explain what nondeterminism is not, and why complement becomes awkward.

3. What survived from Deterministic Finite Automata?

Warm-up

Discussion prompt

Before we open Nondeterministic Finite Automata: without looking back, what was the main idea of Deterministic Finite Automata, 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 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.

4. Letting the Machine Guess

Section

Section 1

5. Two rules are dropped at once

Concept

A nondeterministic finite automaton looks exactly like the machines of Lesson 4, except that two restrictions on the arrows are lifted.

  1. A state may have several arrows carrying the same symbol.
  2. A state may have no arrow for some symbol at all.

The first means the machine faces a choice. The second means a run can simply stop partway through the input, with symbols left unread.

DFANFA
arrows per state per symbolexactly oneany number, including zero
runs on a given inputexactly oneany number, including zero
can it get stuck?neveryes

6. Fill in: DFA for Two rules are dropped at once

Comparison

Comparison matrix

From Two rules are dropped at once: refill the DFA column from what you know. The rest of the table is as it appeared.

DFANFA
arrows per state per symbolexactly oneany number, including zero
runs on a given inputexactly oneany number, including zero
can it get stuck?neveryes

7. Picture several markers, not one

Intuition

The cleanest way to think about it: instead of one marker walking the diagram, imagine a handful of markers, and the handful changes size as you read.

When a marker meets two arrows with the right label, it splits — one copy down each. When it meets none, it dies. Symbols are read by every surviving marker simultaneously.

At any moment the machine's situation is not a single state but a set of states: exactly the states some marker is currently standing on.

\[ \text{situation} \;=\; S \subseteq Q \]

8. Break it if you can: Picture several markers, not one

Counterexample

Discussion prompt

The cleanest way to think about it: instead of one marker walking the diagram, imagine a handful of markers, and the handful changes size as you read.

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:

When a marker meets two arrows with the right label, it splits — one copy down each. When it meets none, it dies. Symbols are read by every surviving marker simultaneously.

9. The active set, and how it advances

Concept

Running the machine means updating that set once per symbol. The rule is a union.

For each state in the current set, collect every state its arrows on the incoming symbol lead to, and take the union of all those collections.

\[ S \;\longmapsto\; \bigcup_{q \in S} \delta(q, a) \]

Nothing else is needed. States with no arrow contribute the empty set and quietly drop out; states with two arrows contribute both destinations.

If the set ever becomes empty it stays empty, because a union of nothing is nothing. That is what 'every branch has died' looks like in this bookkeeping.

\[ S = \varnothing \;\Longrightarrow\; \text{every later set is } \varnothing \]

10. By analogy: The active set, and how it advances

Analogy

Discussion prompt

Explain The active set, and how it advances 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:

Running the machine means updating that set once per symbol. The rule is a union.

11. The active set never needs duplicates

Intuition

Two markers standing on the same state are indistinguishable. Whatever one of them does next, the other does identically, so keeping both is pure bookkeeping waste.

That is why the situation is recorded as a set rather than a list or a multiset. Collapsing duplicates costs nothing and is what keeps the number of distinct situations finite.

It also puts a hard ceiling on the work. However much the machine branches, the active set is a subset of the state set, so it can never have more members than the machine has states.

\[ |S| \le |Q| \quad\text{at every step} \]

12. Teach it back: The active set never needs duplicates

Explain it

Discussion prompt

Explain The active set never needs duplicates 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:

Two markers standing on the same state are indistinguishable. Whatever one of them does next, the other does identically, so keeping both is pure bookkeeping waste.

13. How many situations are possible at all

Concept

Because the active set is a subset, the machine has only finitely many possible situations — and the count is exactly the number of subsets.

\[ \text{possible active sets} \;=\; |\mathcal{P}(Q)| = 2^{|Q|} \]

This is a large number but a finite one, and that observation is the entire idea behind Lesson 6. If there are finitely many situations, each one can be made a state of an ordinary deterministic machine.

Hold on to the number. It is where the exponential cost of determinization comes from, and it is also why that cost cannot in general be avoided.

14. Picture it first: Trace a string as a moving set of states

Picture it

Figure (svg): Automaton with states q0, q1, q2

The start state loops on both symbols and also guesses that the final 01 has begun.

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:

Run the machine below on the input 0010, tracking the active set after each symbol.

15. Trace a string as a moving set of states

Worked example

Run the machine below on the input 0010, tracking the active set after each symbol.

Figure (svg): Automaton with states q0, q1, q2

The start state loops on both symbols and also guesses that the final 01 has begun.

Start with the set holding just the start state

Why: Before any symbol is read there is one marker, on the start state, so the active set is a one-element set.

\[ S_0 = \{q_0\} \]

Read the first 0

Why: From the start state a 0 leads two ways: the self-loop keeps a marker there, and the guessing arrow sends a copy onward. The set grows.

\[ S_1 = \{q_0\} \cup \{q_1\} = \{q_0, q_1\} \]

Read the second 0

Why: The start state again splits into both destinations. The middle state has no 0-arrow at all, so that marker dies and contributes nothing.

\[ S_2 = \{q_0, q_1\} \cup \varnothing = \{q_0, q_1\} \]

Read the 1

Why: The start state's self-loop keeps a marker there. The middle state's 1-arrow reaches the accepting state. Both contributions are unioned.

\[ S_3 = \{q_0\} \cup \{q_2\} = \{q_0, q_2\} \]

Read the final 0

Why: The start state splits as usual. The accepting state has no outgoing arrows at all, so that marker dies — reaching the accepting state early is worth nothing.

\[ S_4 = \{q_0, q_1\} \]

Verify the verdict against the language

Why: The final set misses the accepting state, so 0010 is rejected. That is right: the language is the strings ending in 01, and 0010 ends in 10. The set bookkeeping and the specification agree.

\[ S_4 \cap F = \varnothing \;\Rightarrow\; \text{reject} \ \checkmark \]

16. Decode the notation: Trace a string as a moving set of states

Notation

Annotate

From Trace a string as a moving set of states — read this one piece at a time. What is each part doing?

On: \( S_1 = \{q_0\} \cup \{q_1\} = \{q_0, q_1\} \)

  • Before any symbol is read there is one marker, on the start state, so the active set is a one-element set.
  • From the start state a 0 leads two ways: the self-loop keeps a marker there, and the guessing arrow sends a copy onward. The set grows.
  • The start state again splits into both destinations. The middle state has no 0-arrow at all, so that marker dies and contributes nothing.

17. Rebuild the recipe: How to run a machine by the active set

Ranking

Put in order

These are the steps of How to run a machine by the active set, scrambled. Put them back in order before the next slide shows you.

  1. Write the start state as a one-element set in the first row.
  2. For the next symbol, look up every member's row and take the union of the results.
  3. Write that union as the next row, dropping duplicates.
  4. Repeat until the input is exhausted.
  5. Accept exactly when the final set meets the accepting set.

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.

18. How to run a machine by the active set

Pattern

The procedure never varies, and writing it as a table makes mistakes visible.

  1. Write the start state as a one-element set in the first row.
  2. For the next symbol, look up every member's row and take the union of the results.
  3. Write that union as the next row, dropping duplicates.
  4. Repeat until the input is exhausted.
  5. Accept exactly when the final set meets the accepting set.

Two habits prevent nearly all errors: never let a state appear twice in a set, and never stop early because a set looks promising.

19. Rule out three: Check yourself: the active set

Elimination

Eliminate the wrong options

While running an NFA, the active set becomes empty after reading some prefix. What happens next?

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.

  • A. It stays empty for the rest of the input, and the string is rejected
  • B. The machine restarts from the start state
  • C. The machine rejects immediately without reading the rest
  • D. The empty set counts as accepting if the start state is accepting

Survives elimination: A

Why: The update rule takes a union over the members of the current set. With no members there is nothing to union, so the next set is empty too, and this repeats. The final set is empty, misses the accepting set, and the string is rejected.

20. Check yourself: the active set

Check

Think about what a union of nothing gives.

Check your understanding

While running an NFA, the active set becomes empty after reading some prefix. What happens next?

  • A. It stays empty for the rest of the input, and the string is rejected (correct)
  • B. The machine restarts from the start state
  • C. The machine rejects immediately without reading the rest
  • D. The empty set counts as accepting if the start state is accepting

Answer: A

Why: The update rule takes a union over the members of the current set. With no members there is nothing to union, so the next set is empty too, and this repeats. The final set is empty, misses the accepting set, and the string is rejected.

Why B tempts people
Nothing in the definition restarts anything. Once every branch has died there is no marker left to move.
Why C tempts people
The verdict is the same, but the description is wrong: acceptance is defined by the set after the whole input is read, not by stopping partway.
Why D tempts people
The start state is irrelevant once the run has begun. Acceptance asks whether the FINAL set meets the accepting set, and the empty set meets nothing.

21. Something is wrong here: 'a branch got stuck, so the string is rejected'

Anomaly

Predict first

A student writes this, and it looks reasonable:

Does the machine above accept the string 001?

It is wrong. Say what breaks — and say it before you turn the page.

Correct: After the first 0 the machine guesses the final block has begun and moves to the middle state.

Does the machine above accept the string 001?

Why: After the first 0 the machine guesses the final block has begun and moves to the middle state. The next symbol is another 0, and the middle state has no 0-arrow, so this branch dies. Report reject.

22. Trap: 'a branch got stuck, so the string is rejected'

Trap

The trap

Does the machine above accept the string 001?

Follow the branch that guesses early

Why: After the first 0 the machine guesses the final block has begun and moves to the middle state. The next symbol is another 0, and the middle state has no 0-arrow, so this branch dies. Report reject.

\[ q_0 \xrightarrow{0} q_1 \xrightarrow{0} \text{ (no arrow — branch dies)} \]

Verdict: reject — a branch got stuck partway through.

The fix

Does the machine above accept the string 001?

Follow every branch, then ask whether ANY ends accepting

Why: The branch that waits one symbol before guessing reads 0 and stays, reads the second 0 and guesses, then reads 1 and lands on the accepting state. One surviving accepting path is the entire requirement.

\[ q_0 \xrightarrow{0} q_0 \xrightarrow{0} q_1 \xrightarrow{1} q_2 \in F \]

Verdict: accept — rejection requires every branch to fail, not just one.

23. Say it in words: Trap: 'a branch got stuck, so the string is…

Translation

\( q_0 \xrightarrow{0} q_0 \xrightarrow{0} q_1 \xrightarrow{1} q_2 \in 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.

24. Acceptance: some branch, not every branch

Concept

The acceptance rule is where nondeterminism actually lives, and it is deliberately lopsided.

\[ w \in L(N) \iff \exists \text{ a path from } q_0 \text{ spelling } w \text{ and ending in } F \]

Read the quantifier. One successful path is enough, no matter how many others die or finish in the wrong place. The machine is credited with the best outcome available to it.

In active-set language this becomes a membership test on the final set, which is why the two views agree.

\[ w \in L(N) \iff \hat{\delta}(q_0, w) \cap F \neq \varnothing \]

25. The computation tree

Intuition

A third picture is sometimes the clearest: draw the run as a tree that branches wherever the machine had a choice.

The root is the start state. Each level corresponds to one symbol of the input. A node with two children is a split; a node with none is a branch that died.

The string is accepted exactly when some leaf at the bottom level is an accepting state. Leaves higher up are dead branches and are simply ignored — they neither help nor hurt.

\[ \text{accept} \iff \exists \text{ a leaf at depth } |w| \text{ lying in } F \]

26. What has to happen first: A tree where exactly one branch survives

Ranking

Put in order

Put the moves of A tree where exactly one branch survives into the order they have to happen.

  1. Level one: read the first 0
  2. Level two: read the second 0
  3. Level three: read the 1
  4. Read off the verdict
  5. Verify that the tree and the active set agree

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. The start state has two 0-arrows, so the root has two children — one staying at the start state, one guessing forward to the middle.

27. A tree where exactly one branch survives

Worked example

Run the same machine on 001, but draw the branching explicitly rather than tracking sets.

Level one: read the first 0

Why: The start state has two 0-arrows, so the root has two children — one staying at the start state, one guessing forward to the middle.

Level two: read the second 0

Why: The staying branch splits again into two. The guessing branch is at the middle state, which has no 0-arrow, so that branch ends here as a dead leaf.

\[ \text{live at depth } 2: \{q_0, q_1\} \]

Level three: read the 1

Why: The branch at the start state loops back to itself. The branch at the middle state takes its 1-arrow to the accepting state.

\[ \text{live at depth } 3: \{q_0, q_2\} \]

Read off the verdict

Why: One leaf at the bottom level is the accepting state, so the string is accepted. The branch that died at level two placed no constraint on the answer.

Verify that the tree and the active set agree

Why: Collecting the live states at each depth gives the same sets the active-set method produced: the start state, then both, then both again, then the pair including the accepting state. Two different bookkeeping methods, one answer.

\[ \text{tree leaves at depth } |w| \;=\; \hat{\delta}(q_0, w) \ \checkmark \]

28. A tree where exactly one branch survives — line by line

Picture it

Animation

Shows: Each line of the worked example "A tree where exactly one branch survives", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Collecting the live states at each depth gives the same sets the active-set method produced: the start state, then both, then both again, then the pair including the accepting state. Two different bookkeeping methods, one answer.

29. The Formal Definition

Section

Section 2

30. The same five components, one changed codomain

Concept

The tuple has the same five slots as before. Only the transition function is different, and it is different in exactly one way.

\[ N = (Q, \Sigma, \delta, q_0, F) \]

It no longer returns a state. It returns a set of states — possibly empty, possibly several, possibly one.

\[ \delta : Q \times \Sigma \to \mathcal{P}(Q) \]

That single change encodes both dropped rules at once. Returning the empty set is 'no arrow'; returning a two-element set is 'two arrows'.

31. Why the power set is the right codomain

Concept

Using the power set is not a notational flourish. It is what keeps the function total while allowing zero or many destinations.

A function must return exactly one value for each input, and it does: one set. The multiplicity has been moved inside the value, where it does no harm to the definition.

\[ |\mathcal{P}(Q)| = 2^{|Q|} \]

That count is worth noticing now, because it is exactly the number of possible active sets — and in Lesson 6 it becomes the state count of the equivalent deterministic machine.

32. Epsilon arrows: moving without reading

Concept

Most treatments allow one further extension, and it is the one that makes machines easy to wire together.

epsilon arrow — A transition the machine may take at any moment without consuming an input symbol.

An ε-arrow costs nothing and may always be taken. It is a way of saying 'these two states are, for free, the same place'.

Formally the alphabet is extended with ε for the purposes of the transition function only. The alphabet of the language is unchanged — no string ever contains an ε.

\[ \delta : Q \times \Sigma_{\varepsilon} \to \mathcal{P}(Q), \qquad \Sigma_{\varepsilon} = \Sigma \cup \{\varepsilon\} \]

33. Picture it first: Write the five-tuple for a nondeterministic…

Picture it

Figure (svg): Automaton with states q0, q1, q2

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 ends-in-01 machine into its formal tuple.

34. Write the five-tuple for a nondeterministic machine

Worked example

Convert the ends-in-01 machine into its formal tuple.

Figure (svg): Automaton with states q0, q1, q2

Read off the four easy components

Why: Three circles, two arrow labels, the stub marks the start, and one circle is doubled.

\[ Q = \{q_0,q_1,q_2\}, \; \Sigma = \{0,1\}, \; F = \{q_2\} \]

Write the transition function with set values

Why: Every cell must hold a set, even when that set is empty or has one member. Writing a bare state name here is the most common notational slip.

δ01
-> q0{q0, q1}{q0}
q1{}{q2}
* q2{}{}

Notice the empty cells

Why: Three cells are empty sets. In Lesson 4 that was illegal; here it simply means those branches die, and the function is still perfectly total.

Compare with the deterministic machine for the same language

Why: The DFA of Lesson 4 also used three states, but every cell held exactly one state and the design required naming what each state remembered. This machine needed no such analysis.

Verify the tuple by re-running one string

Why: Running 101 from the table gives the start set, then the pair, then the pair including the accepting state — which meets the accepting set, so 101 is accepted. The string does end in 01, so the table faithfully describes the picture.

\[ \hat{\delta}(q_0, 101) \cap F = \{q_2\} \neq \varnothing \ \checkmark \]

35. Watch it run: Write the five-tuple for a nondeterministic machine

Pattern

Step through it

Step through Write the five-tuple for a nondeterministic machine one row at a time. What is driving the change, and what would the row after the last one be?

  1. Step 1: δ is -> q0
  2. Step 2: δ is q1
  3. Step 3: δ is * q2

36. The set-valued table is the honest picture

Intuition

For a deterministic machine the transition table held single state names. Here every cell holds a set, and that is not extra decoration — it is the actual content of nondeterminism.

Reading the table aloud is the algorithm: 'from the start state on a 0 you may go to the start state, or to the next one'. The word may is what the braces encode.

A useful discipline when writing these tables: always draw the braces, even around a single state, and always write the empty set explicitly rather than leaving a blank. A blank cell is ambiguous between 'no arrow' and 'not filled in yet'.

37. Every deterministic machine is already a nondeterministic one

Concept

The two models are not rivals. One is a special case of the other, and the translation is purely notational.

Given a deterministic machine, wrap every transition value in braces. The result satisfies the nondeterministic definition and behaves identically, since every active set stays a one-element set forever.

\[ \delta_N(q,a) = \{\delta_D(q,a)\} \]

So one direction of the equivalence proved in Lesson 6 is free. The interesting direction — turning a genuinely nondeterministic machine into a deterministic one — is the one that needs work.

38. Plan first: Convert a deterministic machine into a nondeterministic one

Step zero

Discussion prompt

Convert a deterministic machine into a nondeterministic one — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Wrap every transition value in braces

Answer:

  1. Wrap every transition value in braces
  2. Check the new object satisfies the nondeterministic definition
  3. Watch what the active set does
  4. See that acceptance agrees
  5. Verify on a string both machines should accept

39. Convert a deterministic machine into a nondeterministic one

Worked example

Make the special-case claim concrete by converting the ends-in-1 machine from Lesson 4.

Wrap every transition value in braces

Why: Each cell of the deterministic table held one state; each cell of the new table holds the one-element set containing it. Nothing else changes.

δ01
-> q0{q0}{q1}
* q1{q0}{q1}

Check the new object satisfies the nondeterministic definition

Why: The transition function now returns subsets of the state set, which is exactly what the definition requires. Every other component is unchanged.

Watch what the active set does

Why: Starting from a one-element set, each update unions a single one-element set, so the result is again a one-element set. The active set never grows and never empties.

\[ |S_0| = 1 \;\Rightarrow\; |S_i| = 1 \text{ for every } i \]

See that acceptance agrees

Why: A one-element set meets the accepting set exactly when its single member belongs to it. So the membership test reduces to the deterministic one.

Verify on a string both machines should accept

Why: Running 1101 gives the singleton sets holding the accepting state, the accepting state, the start state, and the accepting state — the same four states the deterministic trace visited. Both machines accept, and they would agree on every input for the same reason.

\[ \hat{\delta}(q_0,1101) = \{q_1\}, \quad \{q_1\} \cap F \neq \varnothing \ \checkmark \]

40. Convert a deterministic machine into a… — line by line

Picture it

Animation

Shows: Each line of the worked example "Convert a deterministic machine into a nondeterministic one", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The transition function now returns subsets of the state set, which is exactly what the definition requires. Every other component is unchanged.

41. A variant worth knowing: several start states

Concept

Some textbooks allow a set of start states rather than one. It is a genuine convenience and adds no power whatever.

Running such a machine simply begins with the whole start set as the initial active set, and everything else proceeds unchanged.

\[ S_0 = Q_{\text{start}} \quad \text{instead of} \quad S_0 = \{q_0\} \]

To get back to the single-start definition, add one fresh state and an ε-arrow from it into each old start state. The fresh state consumes nothing, so it changes no verdict.

This is worth recognizing because it appears naturally when reversing a machine in Lesson 7: flipping the arrows turns the accepting set into a set of start states, and the fix is exactly this.

42. Answer it before you see the options: Check yourself: the formal definition

Prediction

Predict first

In the formal definition of an NFA, what is the codomain of the transition function?

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: The power set of the state set

Why: Returning a set is what lets one state-and-symbol pair map to several destinations, to exactly one, or to none. The function stays total and single-valued, because the single value it returns is itself a set.

43. Check yourself: the formal definition

Check

Look carefully at what the transition function returns.

Check your understanding

In the formal definition of an NFA, what is the codomain of the transition function?

  • A. The power set of the state set (correct)
  • B. The state set
  • C. The state set together with a special stuck value
  • D. The set of accepting states

Answer: A

Why: Returning a set is what lets one state-and-symbol pair map to several destinations, to exactly one, or to none. The function stays total and single-valued, because the single value it returns is itself a set.

Why B tempts people
That is the deterministic definition. Returning a bare state allows neither branching nor dying.
Why C tempts people
A special stuck value would handle the no-arrow case but not the several-arrows case, and it is not how the definition is written.
Why D tempts people
The accepting set plays no role in transitions at all. It is consulted only once, after the whole input has been read.

44. Reading a set-valued transition table

Pattern

Given a table with braces in the cells, this recovers the machine and its behaviour.

  1. One circle per row; mark the arrowed row as the start and double the starred rows.
  2. For each cell, draw one arrow per member of the set — none for the empty set.
  3. To run a string, start from the one-element set holding the start state.
  4. Per symbol, look up each member's cell and union the results.
  5. Accept when the final set shares at least one member with the accepting set.

The union step is the only place a mistake can hide. Doing it in writing, set by set, is worth the extra seconds.

45. Epsilon Arrows and Closure

Section

Section 3

46. Epsilon arrows need care in the bookkeeping

Concept

An ε-arrow may be taken at any moment, which means the active set is never quite what the last symbol left behind.

If a marker sits on a state with an ε-arrow leaving it, a copy is also — immediately and for free — on the destination. And if that destination has an ε-arrow too, the same applies again.

So before and after every symbol, the active set must be saturated: closed under following ε-arrows as far as they go. That saturation has a name.

47. The epsilon-closure

Concept

epsilon-closure — The set of all states reachable from a given set using ε-arrows alone, including the states you started from.

Two properties define it, and both are needed. It contains everything you started with, and it is closed under one more ε-step.

\[ E(S) \supseteq S, \qquad E\big(E(S)\big) = E(S) \]

Computing it is a graph reachability problem restricted to ε-arrows: start with the set, repeatedly add anything an ε-arrow reaches, and stop when a full pass adds nothing.

48. Picture it first: Compute an epsilon-closure through a chain

Picture it

Figure (svg): Automaton with states p, r, s

A chain of two epsilon-arrows.

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 has ε-arrows from the start state to a second state, and from that second state on to a third. Compute the closure of the start state.

49. Compute an epsilon-closure through a chain

Worked example

A machine has ε-arrows from the start state to a second state, and from that second state on to a third. Compute the closure of the start state.

Figure (svg): Automaton with states p, r, s

A chain of two epsilon-arrows.

Seed the set with the state itself

Why: The closure always contains what it started with, so begin there.

\[ E_0 = \{p\} \]

Take one round of epsilon-arrows

Why: The start state has an ε-arrow to the middle state, so add it. Nothing else is reachable in one step.

\[ E_1 = \{p, r\} \]

Take another round

Why: The newly added state has its own ε-arrow onward. This is the step people stop one short of — closures follow chains, not single arrows.

\[ E_2 = \{p, r, s\} \]

Take a third round and stop

Why: The last state has no outgoing ε-arrow, so nothing is added. The set is now closed, and that is the answer.

\[ E\big(\{p\}\big) = \{p, r, s\} \]

Verify by checking closure and by asking about the empty string

Why: Applying one more round adds nothing, which is exactly the fixed-point condition. And since the closure of the start state contains an accepting state, the empty string is accepted — reading nothing still lets the machine drift down the chain.

\[ E\big(E(\{p\})\big) = E(\{p\}) \quad\text{and}\quad \varepsilon \in L(N) \ \checkmark \]

50. Decode the notation: Compute an epsilon-closure through a chain

Notation

Annotate

From Compute an epsilon-closure through a chain — read this one piece at a time. What is each part doing?

On: \( E\big(E(\{p\})\big) = E(\{p\}) \quad\text{and}\quad \varepsilon \in L(N) \ \checkmark \)

  • The closure always contains what it started with, so begin there.
  • The start state has an ε-arrow to the middle state, so add it. Nothing else is reachable in one step.
  • The newly added state has its own ε-arrow onward. This is the step people stop one short of — closures follow chains, not single arrows.

51. The extended transition function, with closures

Concept

With closures in hand, the extended transition function for a machine with ε-arrows has the shape you would expect, plus a closure at every stage.

\[ \hat{\delta}(q, \varepsilon) = E\big(\{q\}\big) \]

The base case is already interesting: reading nothing does not leave you at the state you started from, but at everything reachable from it for free.

\[ \hat{\delta}(q, wa) \;=\; E\!\left( \bigcup_{p \in \hat{\delta}(q,w)} \delta(p,a) \right) \]

Read the recursive case as three moves: where could we be after the prefix, where does one symbol take us, and where can we drift for free afterwards.

52. Guess the shape of the answer: Run a machine with epsilon-arrows on a full…

Estimation

Predict first

Take a machine whose start state has an ε-arrow to a second state, where the second state loops on a and the first reads b to an accepting state. Run the input a.

Commit before you compute: what does Run a machine with epsilon-arrows on a full string 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 by checking the step everyone skips

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. Had the opening closure been omitted, the run would have started at the first state alone, which has no a-arrow, and the active set would have died immediately.

53. Run a machine with epsilon-arrows on a full string

Worked example

Take a machine whose start state has an ε-arrow to a second state, where the second state loops on a and the first reads b to an accepting state. Run the input a.

Close the start set before reading anything

Why: The base case closes the one-element start set, so the run begins with two live states rather than one.

\[ S_0 = E\big(\{p_0\}\big) = \{p_0, p_1\} \]

Read the symbol a from every live state

Why: Only the second state has an a-arrow; the first contributes the empty set. Union the results.

\[ \bigcup \delta(\cdot, a) = \varnothing \cup \{p_1\} = \{p_1\} \]

Close again after reading

Why: Check whether any newly reached state has an ε-arrow out of it. Here none does, so the closure changes nothing — but the step must still be performed.

\[ S_1 = E\big(\{p_1\}\big) = \{p_1\} \]

Test the final set against the accepting set

Why: The accepting state is not in the final set, so the input a is rejected by this machine.

\[ S_1 \cap F = \varnothing \]

Verify by checking the step everyone skips

Why: Had the opening closure been omitted, the run would have started at the first state alone, which has no a-arrow, and the active set would have died immediately. The verdict happens to be the same here, but the reason would have been wrong — and on the input b the two methods disagree outright.

\[ E\big(\{p_0\}\big) = \{p_0,p_1\} \neq \{p_0\} \ \checkmark \]

54. Run a machine with epsilon-arrows on a full string — line by line

Picture it

Animation

Shows: Each line of the worked example "Run a machine with epsilon-arrows on a full string", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Had the opening closure been omitted, the run would have started at the first state alone, which has no a-arrow, and the active set would have died immediately. The verdict happens to be the same here, but the reason would have been wrong — and on the input b the two methods disagree outright.

55. Epsilon arrows are wiring, not computation

Intuition

An ε-arrow never consumes input, so it never makes progress through the string. Its whole purpose is to connect machines together.

That is exactly how Lesson 7 builds the closure constructions: to accept the union of two languages, wire a fresh start state to both machines with ε-arrows; to accept their concatenation, wire the accepting states of the first machine to the start state of the second.

Because the wiring costs nothing and consumes nothing, the two machines being joined need to know nothing about each other. That modularity is the real payoff, and it is why Thompson's construction in Lesson 8 is so short.

56. Plan first: Build a union by wiring, using epsilon-arrows

Step zero

Discussion prompt

Build a union by wiring, using epsilon-arrows — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Place both machines side by side

Answer:

  1. Place both machines side by side
  2. Add a fresh start state with two epsilon-arrows
  3. Keep both accepting sets
  4. See why this recognizes the union
  5. Verify on one string from each side and one from neither

57. Build a union by wiring, using epsilon-arrows

Worked example

Given a machine for the strings ending in a and a machine for the strings of even length, build one machine for the union without touching either original.

Place both machines side by side

Why: Rename states if necessary so the two state sets are disjoint. Nothing inside either machine is altered.

\[ Q = \{s\} \cup Q_1 \cup Q_2, \qquad Q_1 \cap Q_2 = \varnothing \]

Add a fresh start state with two epsilon-arrows

Why: The new state has an ε-arrow into each original start state and no other transitions at all.

\[ \delta(s,\varepsilon) = \{q_1, q_2\} \]

Keep both accepting sets

Why: A string should be accepted if either machine would accept it, so the accepting set is the union of the two originals.

\[ F = F_1 \cup F_2 \]

See why this recognizes the union

Why: The opening closure puts a marker at both original start states, so both machines run on the whole input in parallel. The final set meets the accepting set exactly when at least one of them ended accepting.

Verify on one string from each side and one from neither

Why: A string ending in a is accepted through the first branch; a string of even length is accepted through the second; a string that is neither leaves both branches non-accepting and is rejected. The construction adds no strings and loses none.

\[ w \in L_1 \cup L_2 \iff w \in L(N) \ \checkmark \]

58. Build a union by wiring, using epsilon-arrows — line by line

Picture it

Animation

Shows: Each line of the worked example "Build a union by wiring, using epsilon-arrows", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: A string ending in a is accepted through the first branch; a string of even length is accepted through the second; a string that is neither leaves both branches non-accepting and is rejected. The construction adds no strings and loses none.

59. How sure are you: Check yourself: epsilon-closure

Commit first

Predict first

An ε-NFA has an ε-arrow from its start state to a state r, and r is accepting. Is the empty string accepted?

Commit to an answer, then rate it — certain, fairly sure, or guessing — and write the rating down before you turn the page.

Correct: Yes, because the closure of the start state contains r

Why: The extended transition function on the empty string returns the ε-closure of the start state, not the start state itself. That closure contains r, which is accepting, so the final set meets 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.

60. Check yourself: epsilon-closure

Check

Think about what the base case of the extended transition function says.

Check your understanding

An ε-NFA has an ε-arrow from its start state to a state r, and r is accepting. Is the empty string accepted?

  • A. Yes, because the closure of the start state contains r (correct)
  • B. No, because no symbol was read
  • C. Only if the start state is also accepting
  • D. Only if r has no outgoing arrows

Answer: A

Why: The extended transition function on the empty string returns the ε-closure of the start state, not the start state itself. That closure contains r, which is accepting, so the final set meets the accepting set.

Why B tempts people
Reading no symbols does not mean staying put. ε-arrows may be followed at any time, including before the first symbol and when there are no symbols at all.
Why C tempts people
That is the rule for machines without ε-arrows. With them, any accepting state in the closure of the start state does the job.
Why D tempts people
Outgoing arrows from r are irrelevant. Acceptance asks only whether the final set meets the accepting set.

61. Running a machine that has epsilon-arrows

Pattern

Add two closure steps to the ordinary procedure, and never skip either.

  1. Start from the ε-closure of the one-element set holding the start state.
  2. For each symbol, take the union of the transitions from every live state.
  3. Take the ε-closure of that union before moving on.
  4. Repeat for every symbol of the input.
  5. Accept when the final closed set meets the accepting set.

The habit worth building: say 'close, read, close' out loud for each symbol. The forgotten closure is almost always the opening one.

62. Designing With Nondeterminism

Section

Section 4

63. Without one step: The guess-and-verify design recipe

Constraint

Discussion prompt

Run The guess-and-verify design recipe with this step confiscated:

From the waiting state, branch to a chain that verifies the guess.

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:

  1. Describe the language as: somewhere in the string, something happens.
  2. Build a state that waits, looping on every symbol, until it decides to guess.
  3. From the waiting state, branch to a chain that verifies the guess.
  4. Make the end of the verification chain the accepting state.
  5. Check that a wrong guess simply dies, and never wrongly accepts.

64. The guess-and-verify design recipe

Pattern

Nondeterministic design is a different activity from deterministic design, and much easier once the shift is made.

  1. Describe the language as: somewhere in the string, something happens.
  2. Build a state that waits, looping on every symbol, until it decides to guess.
  3. From the waiting state, branch to a chain that verifies the guess.
  4. Make the end of the verification chain the accepting state.
  5. Check that a wrong guess simply dies, and never wrongly accepts.

The last step is the only real obligation. The machine may guess freely, but a wrong guess must lead nowhere — because acceptance credits the best branch.

65. Where does it stop working: The guess-and-verify design recipe

Edge cases

Discussion prompt

The guess-and-verify 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:

Nondeterministic design is a different activity from deterministic design, and much easier once the shift is made.

66. Guess and verify: why it is sound

Concept

It looks like cheating. The machine simply guesses the answer, then confirms it. The acceptance rule is what makes it legitimate.

If the string really is in the language, then some guess is correct, and the branch making that guess verifies successfully. One accepting path exists, so the string is accepted.

If the string is not in the language, then every guess is wrong, and every branch fails its verification. No accepting path exists, so the string is rejected.

\[ \exists \text{ correct guess} \iff w \in L \]

The two halves match the two directions of the acceptance rule exactly, which is why guess-and-verify designs almost prove themselves.

67. Guess the shape of the answer: Design: the third symbol from the end is a 1

Estimation

Predict first

The language that needed exponentially many deterministic states. Guess-and-verify handles it in four.

Commit before you compute: what does Design: the third symbol from the end is a 1 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 a positive and a negative string

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. In 100 the third symbol from the end is the leading 1, and the branch guessing there reaches the accepting state with the input exhausted.

68. Design: the third symbol from the end is a 1

Worked example

The language that needed exponentially many deterministic states. Guess-and-verify handles it in four.

Build the waiting state

Why: One state loops on both symbols. It represents 'still reading, have not committed to anything yet'.

Guess the anchor

Why: From the waiting state, a 1-arrow leaves to a second state. Taking it is the guess that this particular 1 is the third symbol from the end.

Verify by counting off the remaining symbols

Why: Two more arrows follow, each labelled with either symbol, leading to the accepting state. They confirm that exactly two symbols follow the guessed 1.

\[ Q = \{\text{wait}, 1, 2, 3\}, \quad F = \{3\} \]

Check that a wrong guess dies

Why: The accepting state has no outgoing arrows. A branch that guessed too early runs out of arrows before the input ends, so it dies without accepting — which is exactly what a wrong guess must do.

Verify on a positive and a negative string

Why: In 100 the third symbol from the end is the leading 1, and the branch guessing there reaches the accepting state with the input exhausted. In 011 the third from the end is a 0, so no branch can place the guessed 1 correctly and all of them die or finish early.

\[ 100 \in L \qquad 011 \notin L \ \checkmark \]

69. Design: the third symbol from the end is a 1 — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: the third symbol from the end is a 1", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Two more arrows follow, each labelled with either symbol, leading to the accepting state. They confirm that exactly two symbols follow the guessed 1.

70. The state-count contrast

Concept

That example is the standard illustration of what nondeterminism buys, and the gap is not small.

Position from the endNFA statesSmallest DFA states
thirdfoureight
fifthsixthirty-two
k-thk plus onetwo to the k

The deterministic machine must remember the last k symbols exactly, and there are two to the k possibilities. The nondeterministic machine remembers nothing and simply guesses.

\[ \text{NFA: } k+1 \text{ states} \qquad \text{DFA: } 2^{k} \text{ states, and no fewer} \]

Lesson 6 proves the lower bound, so this really is a gap in the machines and not a failure of imagination.

71. Watch it run: The state-count contrast

Pattern

Step through it

Step through The state-count contrast one row at a time. What is driving the change, and what would the row after the last one be?

  1. Step 1: Position from the end is third
  2. Step 2: Position from the end is fifth
  3. Step 3: Position from the end is k-th

72. What has to happen first: Design: contains the block ab

Ranking

Put in order

Put the moves of Design: contains the block ab into the order they have to happen.

  1. Wait, guess, verify, absorb
  2. Make the final state absorbing
  3. Compare with the deterministic design
  4. Confirm no wrong guess can accept
  5. Verify on a positive and a negative string

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. One waiting state looping on both symbols; an a-arrow guessing that the block starts here; a b-arrow completing it; and an accepting state looping on both symbols.

73. Design: contains the block ab

Worked example

A substring condition, which is the archetypal guess-and-verify shape.

Wait, guess, verify, absorb

Why: One waiting state looping on both symbols; an a-arrow guessing that the block starts here; a b-arrow completing it; and an accepting state looping on both symbols.

\[ \text{wait} \xrightarrow{a} \text{saw }a \xrightarrow{b} \text{found} \]

Make the final state absorbing

Why: Once the block has been found the string qualifies regardless of what follows, so the accepting state loops on every symbol.

Compare with the deterministic design

Why: The DFA for the same language needed the longest-suffix analysis of Lesson 4, deciding carefully where to fall back after a partial match. This machine needs none of that: a failed guess simply dies while other branches carry on.

Confirm no wrong guess can accept

Why: The middle state has only a b-arrow. A branch that guessed at an a not followed by a b dies there, and cannot reach the accepting state by any other route.

Verify on a positive and a negative string

Why: The string aab contains the block, and the branch guessing at the second a completes it. The string ba contains no ab, so every branch that guesses at the a dies for want of a following b.

\[ aab \in L \qquad ba \notin L \ \checkmark \]

74. Design: contains the block ab — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: contains the block ab", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The string aab contains the block, and the branch guessing at the second a completes it. The string ba contains no ab, so every branch that guesses at the a dies for want of a following b.

75. Plan first: Design: starts and ends with the same symbol

Step zero

Discussion prompt

Design: starts and ends with the same symbol — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Split into two independent cases

Answer:

  1. Split into two independent cases
  2. Build the a-branch
  3. Build the b-branch identically
  4. Handle the one-symbol case
  5. Verify a positive, a negative, and the one-symbol case

76. Design: starts and ends with the same symbol

Worked example

Two conditions tied together, over the alphabet of a and b. The union structure does the work.

Split into two independent cases

Why: Either the string opens and closes with a, or it opens and closes with b. Build one branch for each and let a fresh start state guess which.

Build the a-branch

Why: Read a leading a, then loop on both symbols, then read a final a into an accepting state. The loop-then-final structure is another guess: the branch guesses which a is the last symbol.

Build the b-branch identically

Why: The same shape with b in place of a. The two branches never interact.

Handle the one-symbol case

Why: The single string a begins and ends with a, but the main branch needs two separate a's. Add a short path accepting a directly, and likewise for b. This is the case that gets forgotten.

\[ L = a\Sigma^{*}a \;\cup\; a \;\cup\; b\Sigma^{*}b \;\cup\; b \]

Verify a positive, a negative, and the one-symbol case

Why: The string abba opens and closes with a and is accepted by the a-branch. The string abb opens with a and closes with b, so both branches fail. The single symbol a is accepted only by the short path added in the previous step, which is why that step was necessary.

\[ abba,\ a \in L \qquad abb \notin L \ \checkmark \]

77. Design: starts and ends with the same symbol — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: starts and ends with the same symbol", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The string abba opens and closes with a and is accepted by the a-branch. The string abb opens with a and closes with b, so both branches fail. The single symbol a is accepted only by the short path added in the previous step, which is why that step was necessary.

78. Reading a machine backwards is often easiest

Intuition

Many nondeterministic designs are clearer read from the accepting state backwards, because that is where the verification chain ends.

Ask: what must the last few symbols look like for a branch to be sitting in an accepting state right now? The chain of arrows leading into the accepting set answers exactly that.

For the third-from-the-end machine, the last two arrows say 'two arbitrary symbols' and the arrow before them says 'a 1'. Reading backwards, the accepting condition is literally a 1 followed by two of anything — which is the specification, restated.

\[ L = \Sigma^{*}\,1\,\Sigma\,\Sigma \]

79. State the rule before it runs: Design: length divisible by two or by…

Hypothesis

Predict first

Design: length divisible by two or by three 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 cycles separately

Why: A two-state cycle accepts the even lengths; a three-state cycle accepts the lengths divisible by three. Each cycle advances on every symbol.

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.

80. Design: length divisible by two or by three

Worked example

A union of two modular conditions, wired with ε-arrows rather than built as a product.

Build the two cycles separately

Why: A two-state cycle accepts the even lengths; a three-state cycle accepts the lengths divisible by three. Each cycle advances on every symbol.

\[ L = \{\, w : |w| \equiv 0 \bmod 2 \; \text{ or } \; |w| \equiv 0 \bmod 3 \,\} \]

Wire a fresh start state into both

Why: Two ε-arrows, one into each cycle's start. The guess of which condition to satisfy is made before any symbol is read.

Keep both accepting sets

Why: Each cycle's own accepting state stays accepting, so either route can carry the string.

\[ |Q| = 1 + 2 + 3 = 6 \]

Contrast with the product construction

Why: A deterministic product machine would need six states too, but every one of them would have to track both remainders at once. Here each state tracks only one, and the ε-arrows do the combining.

Verify one string of each length class

Why: Length 4 is divisible by 2 and accepted down the first branch. Length 3 is divisible by 3 and accepted down the second. Length 5 is divisible by neither, so both branches finish on non-accepting states and it is rejected.

\[ |w| = 4 \text{ accept}, \quad |w| = 3 \text{ accept}, \quad |w| = 5 \text{ reject} \ \checkmark \]

81. Design: length divisible by two or by three — line by line

Picture it

Animation

Shows: Each line of the worked example "Design: length divisible by two or by three", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Length 4 is divisible by 2 and accepted down the first branch. Length 3 is divisible by 3 and accepted down the second. Length 5 is divisible by neither, so both branches finish on non-accepting states and it is rejected.

82. Answer it before you see the options: Check yourself: designing with guesses

Prediction

Predict first

In a guess-and-verify NFA design, what must be true of a branch that guesses incorrectly?

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: It must die or finish in a non-accepting state

Why: Acceptance credits the best branch, so a wrong guess is harmless as long as it never reaches an accepting state with the input exhausted. Letting it die for want of an arrow is the usual and simplest way to arrange that.

83. Check yourself: designing with guesses

Check

Think about what must happen when the guess is wrong.

Check your understanding

In a guess-and-verify NFA design, what must be true of a branch that guesses incorrectly?

  • A. It must die or finish in a non-accepting state (correct)
  • B. It must return to the start state and try again
  • C. It must be removed from the diagram
  • D. It must be prevented from being taken at all

Answer: A

Why: Acceptance credits the best branch, so a wrong guess is harmless as long as it never reaches an accepting state with the input exhausted. Letting it die for want of an arrow is the usual and simplest way to arrange that.

Why B tempts people
There is no retry mechanism. Every branch runs forward independently, and none of them communicate.
Why C tempts people
The branch is a consequence of the arrows drawn, not a separate object. If it could be removed the machine would be deterministic.
Why D tempts people
Preventing wrong guesses would require the machine to know the answer in advance, which is exactly what it cannot do. Allowing them freely is the point.

84. Something is wrong here: complementing by swapping the accepting set

Anomaly

Predict first

A student writes this, and it looks reasonable:

A machine has a start state with two a-arrows: one self-loop and one to an accepting state. Complement it by the Lesson 4 method.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Lesson 4 complemented a machine by replacing the accepting set with its complement, changing nothing else.

A machine has a start state with two a-arrows: one self-loop and one to an accepting state. Complement it by the Lesson 4 method.

Why: Lesson 4 complemented a machine by replacing the accepting set with its complement, changing nothing else. Apply the same move here.

85. Trap: complementing by swapping the accepting set

Trap

The trap

A machine has a start state with two a-arrows: one self-loop and one to an accepting state. Complement it by the Lesson 4 method.

Swap the accepting set, as with a deterministic machine

Why: Lesson 4 complemented a machine by replacing the accepting set with its complement, changing nothing else. Apply the same move here.

\[ F = \{n_1\} \;\longmapsto\; F' = \{n_0\} \]

Claim the complement

Why: The paths are unchanged, so surely the verdicts are all negated, exactly as before.

\[ L(N') \overset{?}{=} \overline{L(N)} \]

The fix

A machine has a start state with two a-arrows: one self-loop and one to an accepting state. Complement it by the Lesson 4 method.

Check what the active set actually does

Why: On the input a the active set is both states at once. It meets the old accepting set, so a was accepted; and it meets the new one too, so a is accepted again.

\[ \hat{\delta}(n_0, a) = \{n_0, n_1\} \]

Exhibit the failure

Why: The string a is accepted by both machines, so the second is not the complement of the first. The deterministic argument needed exactly one final state per input, and that is precisely what was given up.

\[ a \in L(N) \; \text{ and } \; a \in L(N') \;\Rightarrow\; L(N') \neq \overline{L(N)} \]

State the correct route

Why: To complement a nondeterministic machine, first convert it to a deterministic one, then swap. The conversion is the subset construction of Lesson 6, and this failure is the reason that construction is needed.

\[ N \;\longrightarrow\; \text{DFA} \;\longrightarrow\; \text{swap } F \]

86. Which of these survive contact with Nondeterministic Finite Automata?

Two truths and a lie

Sort into buckets

Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.

Holds up
A nondeterministic finite automaton looks exactly like the machines of Lesson 4, except that two restrictions on the arrows are lifted.; The cleanest way to think about it: instead of one marker walking the diagram, imagine a handful of markers, and the handful changes size as you read.; Running the machine means updating that set once per symbol. The rule is a union.
Breaks
Does the machine above accept the string 001?; A machine has a start state with two a-arrows: one self-loop and one to an accepting state. Complement it by the Lesson 4 method.
sound
These are stated as this lesson states them — each one survives the edge cases Nondeterministic Finite Automata puts it through.
flawed
Each of these is lifted from a trap in this deck: reasonable-sounding, and wrong in a way that only shows up once you rely on it.

87. Plan first: Watch the complement failure in full

Step zero

Discussion prompt

Watch the complement failure in full — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Find the language of the machine as drawn

Answer:

  1. Find the language of the machine as drawn
  2. Find the language after swapping
  3. Compare with the true complement
  4. Diagnose the cause precisely
  5. Verify the diagnosis on the culprit string

88. Watch the complement failure in full

Worked example

Take the machine from the trap and work out both languages explicitly.

Find the language of the machine as drawn

Why: From the start state an a leads to both states. On any nonempty run of a's the active set is both states, which meets the accepting set. On the empty string the set is just the start state, which does not.

\[ L(N) = \{a, aa, aaa, \dots\} = a^{+} \]

Find the language after swapping

Why: The active sets are identical, because no transition changed. Now the start state is accepting, so every set containing it qualifies — including the opening set.

\[ L(N') = a^{*} \]

Compare with the true complement

Why: The complement of the first language, over this one-symbol alphabet, holds only the empty string. The swapped machine accepts every string instead.

\[ \overline{L(N)} = \{\varepsilon\} \neq a^{*} = L(N') \]

Diagnose the cause precisely

Why: The deterministic argument relied on there being exactly one final state per input, so that negating the membership test negated the answer. Here the final set can meet both the accepting set and its complement at once.

Verify the diagnosis on the culprit string

Why: On the input a the final set holds both states. It meets the old accepting set and the new one simultaneously, so no swap of accepting states could ever have negated this verdict. The failure is structural, not arithmetic.

\[ \{n_0,n_1\} \cap F \neq \varnothing \; \text{ and } \; \{n_0,n_1\} \cap F' \neq \varnothing \ \checkmark \]

89. Watch the complement failure in full — line by line

Picture it

Animation

Shows: Each line of the worked example "Watch the complement failure in full", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: On the input a the final set holds both states. It meets the old accepting set and the new one simultaneously, so no swap of accepting states could ever have negated this verdict. The failure is structural, not arithmetic.

90. What Nondeterminism Is and Is Not

Section

Section 5

91. Three things nondeterminism is not

Concept

The word invites bad analogies. Three of them are worth ruling out explicitly.

Not randomness
No probabilities are involved. The machine is not likely to accept; it either has an accepting path or it does not.
Not parallelism
Nothing is executing concurrently. The branches are a mathematical device, not threads.
Not magic lookahead
The machine never learns the future. Every branch is a legal path that was always there in the diagram.

What it actually is: an existential quantifier over paths, dressed as a machine. That is the whole content of the definition.

92. Which is which: Three things nondeterminism is not

Matching

Match the pairs

From Three things nondeterminism is not — match each one to what it actually does. The descriptions have been shuffled.

  • c1. Not randomness
  • c2. Not parallelism
  • c3. Not magic lookahead
  • b1. No probabilities are involved. The machine is not likely to accept; it either has an accepting path or it does not.
  • b2. Nothing is executing concurrently. The branches are a mathematical device, not threads.
  • b3. The machine never learns the future. Every branch is a legal path that was always there in the diagram.

Why: Not randomness, Not parallelism, Not magic lookahead are easy to tell apart while they are sitting next to their descriptions and much harder afterwards, which is what this checks.

93. The quantifier explains the asymmetry

Intuition

Seeing acceptance as a quantifier explains immediately why some operations are easy here and others are painful.

Acceptance says a path exists. Union is easy because a path in either machine is still a path. Rejection, though, says no path exists — and negating an existential gives a universal, which the machine has no direct way to check.

\[ \neg \exists\, b \,.\, \mathrm{acc}(b) \;\equiv\; \forall\, b \,.\, \neg\,\mathrm{acc}(b) \]

That is why complement needs determinization first: a deterministic machine has exactly one path, so the existential and the universal coincide and negation becomes trivial again.

94. Which operations stay easy

Concept

Sorting the operations by whether the quantifier cooperates predicts the constructions of Lesson 7 before any of them are built.

OperationOn an NFAWhy
unioneasy: wire a fresh starta path in either machine still exists
concatenationeasy: wire the joinguess where to split
stareasy: wire a loop backguess how many repetitions
complementawkward: determinize firstneeds 'no path exists'
intersectionawkward: product or determinizeneeds two paths at once

Every easy row is a guess. Every awkward row is a claim about all branches at once.

95. Fill in: On an NFA for Which operations stay easy

Comparison

Comparison matrix

From Which operations stay easy: refill the On an NFA column from what you know. The rest of the table is as it appeared.

OperationOn an NFAWhy
unioneasy: wire a fresh starta path in either machine still exists
concatenationeasy: wire the joinguess where to split
stareasy: wire a loop backguess how many repetitions
complementawkward: determinize firstneeds 'no path exists'
intersectionawkward: product or determinizeneeds two paths at once

96. What has to happen first: Two edge-case machines worth building once

Ranking

Put in order

Put the moves of Two edge-case machines worth building once into the order they have to happen.

  1. Build a machine for the empty language
  2. Build a machine for the empty string alone
  3. Note how little separates them
  4. Note why these two matter later
  5. Verify each accepts exactly what it should

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. One state, no accepting states, and no arrows.

97. Two edge-case machines worth building once

Worked example

Two tiny machines come up constantly in later constructions. Build both now so they are never in doubt.

Build a machine for the empty language

Why: One state, no accepting states, and no arrows. Every input dies immediately or finishes non-accepting, so nothing is ever accepted.

\[ N_{\varnothing}: \quad Q = \{q_0\}, \; \delta(q_0,a) = \varnothing, \; F = \varnothing \]

Build a machine for the empty string alone

Why: One state, accepting, with no arrows out of it. Reading nothing leaves the machine accepting; reading anything at all kills the only branch.

\[ N_{\{\varepsilon\}}: \quad Q = \{q_0\}, \; \delta(q_0,a) = \varnothing, \; F = \{q_0\} \]

Note how little separates them

Why: The two machines differ in exactly one bit: whether the single state is accepting. Yet one recognizes nothing and the other recognizes one string.

Note why these two matter later

Why: They are the base cases of Thompson's construction in Lesson 8, where every regular expression is built up from atoms. Getting them wrong corrupts every expression built on top.

Verify each accepts exactly what it should

Why: The first has no accepting state at all, so no final set can ever meet the accepting set and its language is genuinely empty. The second accepts precisely when nothing has been read, since any symbol kills the only branch.

\[ L(N_{\varnothing}) = \varnothing, \qquad L(N_{\{\varepsilon\}}) = \{\varepsilon\} \ \checkmark \]

98. Two edge-case machines worth building once — line by line

Picture it

Animation

Shows: Each line of the worked example "Two edge-case machines worth building once", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The first has no accepting state at all, so no final set can ever meet the accepting set and its language is genuinely empty. The second accepts precisely when nothing has been read, since any symbol kills the only branch.

99. Where nondeterminism actually pays off

Intuition

It is worth being precise about what was gained, since the class of recognizable languages did not change at all.

What was lost is equally concrete: running the machine now costs work proportional to the size of the active set, and complementing it requires a detour through determinization.

\[ \text{easy to write} \;\longleftrightarrow\; \text{costly to run} \]

100. Teach it back: Where nondeterminism actually pays off

Explain it

Discussion prompt

Explain Where nondeterminism actually pays off 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:

What was lost is equally concrete: running the machine now costs work proportional to the size of the active set, and complementing it requires a detour through determinization.

101. Rule out three: Check yourself: what nondeterminism means

Elimination

Eliminate the wrong options

An NFA rejects a string exactly when which condition holds?

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.

  • A. Every path spelling the string fails to end in an accepting state
  • B. Some path spelling the string fails to end in an accepting state
  • C. At least one branch dies partway through
  • D. The majority of branches end in non-accepting states

Survives elimination: A

Why: Acceptance is existential — one good path is enough — so rejection is universal. Every path must fail, whether by dying early or by ending on a non-accepting state.

102. Check yourself: what nondeterminism means

Check

Recall which quantifier acceptance uses.

Check your understanding

An NFA rejects a string exactly when which condition holds?

  • A. Every path spelling the string fails to end in an accepting state (correct)
  • B. Some path spelling the string fails to end in an accepting state
  • C. At least one branch dies partway through
  • D. The majority of branches end in non-accepting states

Answer: A

Why: Acceptance is existential — one good path is enough — so rejection is universal. Every path must fail, whether by dying early or by ending on a non-accepting state.

Why B tempts people
Some path failing is entirely compatible with acceptance. Most useful designs have failing branches on nearly every input.
Why C tempts people
A dying branch is one failing path. It says nothing about the others, and the trap earlier in this lesson turned on exactly that mistake.
Why D tempts people
Counting branches plays no role anywhere in the definition. One accepting path outweighs any number of failing ones.

103. Sanity checks for a machine you just designed

Pattern

Nondeterministic designs fail differently from deterministic ones, so the checklist is different too.

  1. Test the empty string, remembering to take the ε-closure of the start state first.
  2. Test the shortest member of the language, and the shortest non-member.
  3. For each accepting state, ask what the last few symbols must have been — it should restate the specification.
  4. Confirm every wrong guess dies, by checking that no verification chain can be exited early.
  5. Do not test by following one branch. Track the whole active set, in writing.

The fourth item catches the only error nondeterminism makes easy: a machine that accepts too much because a half-finished verification could still reach an accepting state.

104. Where these machines show up in practice

Concept

The model is not only a proof device. It is what sits underneath a large class of real pattern-matching tools.

The trade-off is always the same one. Simulating the active set costs work proportional to its size on every symbol; determinizing pays that cost once, in advance, and risks the exponential blowup.

\[ \text{simulate: } O(|Q| \cdot |w|) \qquad \text{determinize: } O(2^{|Q|}) \text{ once} \]

105. By analogy: Where these machines show up in practice

Analogy

Discussion prompt

Explain Where these machines show up in practice 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:

The model is not only a proof device. It is what sits underneath a large class of real pattern-matching tools.

106. Rebuild the recipe: Choosing between a deterministic and a…

Ranking

Put in order

These are the steps of Choosing between a deterministic and a nondeterministic…, scrambled. Put them back in order before the next slide shows you.

  1. Reach for nondeterminism when the specification says 'somewhere' or 'either' — guess-and-verify will be short.
  2. Reach for determinism when you must complement or intersect, since those need one path per input.
  3. Reach for determinism when the machine will be run many times and must be fast.
  4. Design nondeterministically first, then determinize if needed — it is nearly always the easier order.
  5. If the design needs an unbounded count, neither model will help, and Lesson 10 will say why.

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.

107. Choosing between a deterministic and a nondeterministic design

Pattern

Both models recognize the same languages, so the choice is about what you are optimizing.

  1. Reach for nondeterminism when the specification says 'somewhere' or 'either' — guess-and-verify will be short.
  2. Reach for determinism when you must complement or intersect, since those need one path per input.
  3. Reach for determinism when the machine will be run many times and must be fast.
  4. Design nondeterministically first, then determinize if needed — it is nearly always the easier order.
  5. If the design needs an unbounded count, neither model will help, and Lesson 10 will say why.

The fourth line is the practical summary of this lesson and the next: write the easy machine, and let a mechanical construction produce the fast one.

108. Where this shows up: Nondeterministic Finite Automata

Real world

Discussion prompt

Outside this lesson: where does Nondeterministic 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 Choosing between a deterministic and a nondeterministic… 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 5 drops the determinism requirement and lets a machine take several arrows on one symbol, or none at all. It covers the active-set method of running such a machine, acceptance as an existential claim over paths, and the computation tree, then gives the five-tuple with its set-valued transition function, epsilon-arrows and epsilon-closure, and the extended transition function with closures. It closes with guess-and-verify design and the exponential saving in states it can produce, why swapping the accepting set fails to complement an NFA, and what nondeterminism is not.

109. What comes next: the same power, cheaper

Concept

Everything so far suggests these machines are stronger than deterministic ones. They are not.

Lesson 6 proves that every nondeterministic machine — ε-arrows and all — can be converted into a deterministic one recognizing exactly the same language. The construction turns each active set into a single state, and the two-to-the-n count from earlier in this lesson is where its cost comes from.

\[ \Sigma_{\varepsilon}\text{-NFA} \; \equiv \text{NFA} \; \equiv \text{DFA} \]

So nondeterminism is a convenience, not a capability. It changes how much you have to write, never what you can recognize — and that is a genuinely surprising theorem, since the same is emphatically not true for the machines of Lesson 20.

110. Break it if you can: What comes next: the same power, cheaper

Counterexample

Discussion prompt

Everything so far suggests these machines are stronger than deterministic ones. They are not.

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.

111. Connect it up: Nondeterministic Finite Automata

Connect it up

Draw it

One page, no notation unless you need it: draw how these connect — Letting the Machine Guess · The Formal Definition · Epsilon Arrows and Closure · Designing With Nondeterminism · What Nondeterminism Is and Is Not. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.

112. What you can do now

Recap

You can run, specify, and design machines that branch — and you know the one place the convenience has to be paid for.

SituationMove
a string to testclose, read, close — and track the whole set
somewhere in the string, something happenswait, guess, verify
two languages to combinewire a fresh start with ε-arrows
the opposite languagedeterminize first, then swap
a design that accepts too muchcheck that no verification chain exits early

Lesson 6 proves these machines are exactly as powerful as the deterministic ones, by turning every active set into a state.

Sources

  1. Sipser, Introduction to the Theory of Computation, 3rd ed., Ch. 1.2 (Nondeterminism) — Cengage, 2013.
  2. Hopcroft, Motwani & Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Ch. 2.3-2.5 (NFAs and epsilon-transitions) — Pearson, 2007.
  3. Rabin & Scott, 'Finite Automata and Their Decision Problems', IBM Journal of Research and Development 3(2) — IBM, 1959.
  4. Lewis & Papadimitriou, Elements of the Theory of Computation, 2nd ed., Ch. 2.2 — Prentice Hall, 1998.
  5. Every active-set trace, closure and state count in this deck was checked by hand, including the empty-string boundary cases. — Verified 2026-08-03.

Want this taught 1-on-1? Alexander tutors Theory of Computation — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108