4.6.21 · D3Theory of Computation

Worked examples — Complexity — DTIME, DSPACE, complexity classes

3,607 words16 min readBack to topic

Before any symbol appears, recall the three plain-word ideas we lean on everywhere:

  • Time = the largest number of steps the machine takes over all inputs of length . (, the number of characters in the input.)
  • Space = the largest number of distinct tape cells the machine ever writes to, over inputs of length .
  • A class like is just a bucket: the set of all problems whose (or ) fits under a stated ceiling.

Everything below is "measure the ceiling, then drop the problem in the smallest bucket that holds it."


The scenario matrix

Every complexity-classification question is one of these cells. Each worked example is tagged with the cell(s) it hits.

Cell What makes it that case Example
C1 — pure time bound count steps, fit into Ex 1
C2 — pure space bound count cells, ignore steps, fit into Ex 2
C3 — "same problem, two buckets" show a problem sits in a small AND a large class Ex 3
C4 — nondeterministic guess use a guess-and-check machine (-classes) Ex 4
C5 — degenerate / edge input , empty graph, single node — does the bound survive? Ex 5
C6 — limiting / boundary of a bound is really enough? where does it break? Ex 6
C7 — real-world word problem translate English → resource count Ex 7
C8 — exam twist (a trap) a tempting-but-wrong classification Ex 8

The rule used in every cell:


Example 1 — Counting characters (Cell C1: pure time)


Example 2 — Same problem, but now count cells (Cell C2: pure space)

Recall Why C1 and C2 give different classes for one problem

Time and space are different rulers. This one problem is time and space. That is not a contradiction: Step 1 of the parent chain says time space, and indeed . See Space vs Time Tradeoffs.


Example 3 — Palindromes in two buckets at once (Cell C3)


Example 4 — Reachability by guessing (Cell C4: nondeterminism)


Example 5 — Degenerate inputs: does the bound survive and one-node graphs? (Cell C5)


Example 6 — The limiting boundary: when is not enough? (Cell C6)


Example 7 — Real-world word problem (Cell C7)

Before this example we need one symbol the parent note named but did not unpack: .


Example 8 — The exam twist / trap (Cell C8)


Recall

Recall One problem, two rulers — what class was palindrome?

PAL is in both (time ) and (space ). ::: Time and space are independent ceilings.

Which cell needs a nondeterministic guess to stay in a small class?
Cell C4 — by guessing the next node with only cur + cnt.
Why does copying the input onto the work tape kick you out of ?
It costs cells; logspace only allows work cells (pointers into the read-only input, not copies).
Can "problem is in and in " prove ?
No — overlap of one language never proves class equality; is the only proven strict gap.