← Student tools · Problem 18 · Lecture 9 · Round 2 (30 pts)

Single-tape TM on {0ⁿ1ⁿ} · O(n²) by pairing

Watch a single-tape TM shuttle back and forth; step counter grows quadratically.

CLO-3R2·30 ptsL9
🔊 Listen

The language {0n1n : n ≥ 0} demands equal counts of 0s followed by equal counts of 1s. On a single-tape Turing machine with one head, you cannot count both groups in parallel — you have one moving part. Sipser's canonical algorithm (Example 7.2) uses the only strategy available: pair off one 0 with one 1, mark them both, rewind, repeat.

Time analysis

Each pair-off requires an O(n) round-trip across the input. There are n/2 pairs to match. Total: Θ(n²). The lower bound is also Θ(n²), proven by a crossing-sequence argument: the head must cross the input's middle Θ(n) times to communicate information between the 0-region and the 1-region.

The two-tape contrast: a 2-tape TM solves the same problem in O(n). Copy 0s to tape 2, then march tape 1 right through the 1s while tape 2 marches left through the copied 0s, both in sync. Quadratic-vs-linear is the price of having only one tape.

🔊 Listen

Trace the algorithm on "000111" (n = 3 pairs):

For n = 3, ≈ 18 steps. For n = 6, ≈ 72 steps. Doubling input quadruples work — the quadratic signature.

🔊 Listen
Watch the pair-off strategy Auto-plays
Step 0
Phase find0
Verdict
🔊 Listen
🔊 Listen
🔊 Listen

Sipser: Example 7.2 (the pair-off algorithm), Theorem 7.8 (multi-tape simulation). Lecture notes: Module 4 slides 3–4. Companion problem: P19 (two-tape race).