Sub topic 3
Designing Turing Machines by Marking Symbols
Assume you know finite automata, context-free languages, and how a Turing machine (TM) uses a tape, a head, and states. This chapter uses a deterministic TM with a two-way infinite tape. The blank symbol is _.
The notation \(a^n b^n\) means a string with \(n\) copies of a followed by \(n\) copies of b. For example, aabb belongs to this language. The empty string belongs when \(n=0\).
The marking method for \(a^n b^n\)
A finite automaton cannot remember how many a symbols it has seen. A TM can use its tape as memory. It marks each matched pair:
- Replace the next unmarked
awithX. - Move right and replace the next unmarked
bwithY. - Return to the left end.
- Repeat.
- When no unmarked
aremains, accept only if no unmarkedbremains.
The symbols X and Y are work symbols. They record which input symbols have already been matched.
| Phase | Action | Reject when |
|---|---|---|
| Find `a` | Scan from the left for an unmarked `a` | An unmarked `b` appears before a needed `a` |
| Match `b` | Move right to the first unmarked `b` | The tape reaches blank first |
| Return | Move left to the beginning | The machine has no valid return path |
| Final check | Confirm that only `X`, `Y`, and blank remain | An unmarked `b` remains |
The machine accepts aabb by changing the tape through stages such as:
aabb → Xabb → XaYb → XXYb → XXYYThe exact intermediate positions of the head are part of the machine's configurations, but the markings show the main idea.
Extending the method to \(a^n b^n c^n\)
For \(a^n b^n c^n\), each round must match three symbols. Use three markers:
Xmarks a useda.Ymarks a usedb.Zmarks a usedc.
One round performs this sequence:
- Find the leftmost unmarked
aand replace it withX. - Move right, skipping marked symbols, and replace the next unmarked
bwithY. - Continue right and replace the next unmarked
cwithZ. - Return to the left end and begin another round.
The machine rejects if it finds a c before the required b, if a required symbol is missing, or if the input order is wrong. After all a symbols are marked, it performs a final check. Any unmarked b or c causes rejection.
A useful correctness invariant is: after \(k\) complete rounds, exactly \(k\) symbols from each required block have been marked. Therefore, the machine accepts precisely when all three blocks have the same length.
>callout note > Marking does not reorder the input. The machine must still check that every a comes before every b, and every b comes before every c.
Exercise
What should the machine do on aabcc while recognizing a^n b^n c^n?
Show answer
It marks the first a, the first b, and the first c. On the second round, it marks the second a but cannot find a second unmarked b, so it rejects.