4.6.21Theory of Computation

Complexity — DTIME, DSPACE, complexity classes

2,392 words11 min readdifficulty · medium

1. WHY we measure as a function of input size


2. DTIME and DSPACE — the atomic building blocks

WHAT they are: sets of languages (decision problems), not single problems. WHY O()O(\cdot): by the linear speedup / tape-compression theorems, constant factors and finite tape-alphabet tricks can shrink time/space by any constant, so only the asymptotic class matters.


3. Building named classes from DTIME / DSPACE


4. Deriving the inclusion hierarchy from first principles

This is the part to derive, not memorize. We prove each step.

Figure — Complexity — DTIME, DSPACE, complexity classes

5. The Hierarchy Theorems — why bigger budget = strictly more power


6. Worked examples


7. Common mistakes (Steel-manned)


8. Forecast-then-Verify

Recall Forecast before peeking

Q: Which is known strict: P\mathsf{P} vs NP\mathsf{NP}, or P\mathsf{P} vs EXP\mathsf{EXP}? Why?

A: PEXP\mathsf{P}\subsetneq\mathsf{EXP} is known (Time Hierarchy: more time of the same kind via diagonalization). P\mathsf{P} vs NP\mathsf{NP} is open because diagonalization compares the same resource at different budgets, but D-vs-N is a different kind of change — hierarchy theorems don't apply, and "relativization barriers" show simple diagonalization can't settle it.


9. Flashcards

What does DTIME(f(n))\mathrm{DTIME}(f(n)) contain?
All languages decided by some deterministic TM in O(f(n))O(f(n)) steps (worst case).
Define P\mathsf{P} in terms of DTIME.
P=kDTIME(nk)\mathsf{P}=\bigcup_k \mathrm{DTIME}(n^k) — polynomial deterministic time.
Why time ff \Rightarrow space f\le f?
The head moves 1\le 1 cell per step, so in ff steps it visits f+1\le f{+}1 cells.
Why does DSPACE(f)(f)\subseteq DTIME(2O(f))(2^{O(f)})?
A halting machine can't repeat a configuration; there are only 2O(f)2^{O(f)} configurations.
State the standard inclusion chain.
LNLPNPPSPACEEXP\mathsf{L}\subseteq\mathsf{NL}\subseteq\mathsf{P}\subseteq\mathsf{NP}\subseteq\mathsf{PSPACE}\subseteq\mathsf{EXP}.
What does NP stand for / mean?
Nondeterministic Polynomial time = solutions verifiable in poly time.
State Savitch's theorem.
NSPACE(f)DSPACE(f2)\mathrm{NSPACE}(f)\subseteq\mathrm{DSPACE}(f^2), so NPSPACE=PSPACE\mathsf{NPSPACE}=\mathsf{PSPACE}.
Which separation is proved, PEXP\mathsf{P}{\ne}\mathsf{EXP} or PNP\mathsf{P}{\ne}\mathsf{NP}?
PEXP\mathsf{P}\ne\mathsf{EXP} (Time Hierarchy Theorem). P\mathsf{P} vs NP\mathsf{NP} is open.
Why is P\mathsf{P} the "efficient" class?
Polynomials are closed under composition, so chaining efficient steps stays efficient.
Which complexity class is graph reachability complete for?
NL\mathsf{NL} (guess the path one node at a time using O(logn)O(\log n) space).
Why the flognf\ge\log n condition for space classes?
Below logn\log n you can't store a pointer into the input; needed for config counting.

Recall Feynman: explain to a 12-year-old

Imagine solving puzzles. Time is how many moves you make; space is how big a scratchpad you need. We sort puzzles into boxes by how many moves or how much paper they need. The "easy box" (P\mathsf{P}) holds puzzles where moves grow gently as the puzzle gets bigger — like n2n^2, not 2n2^n. One neat trick: you can never scribble on more pieces of paper than the number of moves you make (each move touches at most one new spot). And if you only use a tiny notebook, you can't go on forever without repeating an exact notebook-state and looping — so a small notebook secretly limits how long you can run. Some boxes are provably bigger than others (more time really lets you solve more), but the most famous question — does guessing the answer help you find it faster (P\mathsf{P} vs NP\mathsf{NP}) — nobody has solved yet.


Connections

  • Turing Machines — the model whose steps/cells we are counting.
  • NP-Completeness and Reductions — hardest problems inside NP\mathsf{NP}; defines the frontier.
  • Savitch's Theorem — collapses nondeterministic space.
  • Hierarchy Theorems — diagonalization proving strict separations.
  • Decidability and the Halting Problem — computability layer beneath complexity.
  • Big-O Asymptotic Notation — why constant factors vanish in these definitions.
  • Space vs Time Tradeoffs — engineering analogue of DTIME\mathrm{DTIME} vs DSPACE\mathrm{DSPACE}.

Concept Map

measured by

defines

defines

swap D for N

swap D for N

union over n^k

union over n^k

union over 2^n^k

log n

union over n^k

log n

time bounds space

contributes to

ordered by

Resources: time and space

Cost as f of n

DTIME f

DSPACE f

Nondeterministic N variants

Class P polynomial time

Class NP

Class EXP

Class L log space

Class NL

Class PSPACE

Inclusion hierarchy

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, complexity theory ka core idea simple hai: hum poochte hain "problem solve ho sakti hai?" (woh computability hai) aur uske baad "kya woh reasonable time aur memory me solve hogi?" — yahi complexity hai. Do main resources hain — time (kitne steps lagte hain) aur space (kitni tape ya memory chahiye). Inhe hum hamesha input size nn ke function ke roop me likhte hain, kyunki bada input matlab zyada kaam. DTIME(f)\mathrm{DTIME}(f) matlab "saari problems jo deterministic TM O(f(n))O(f(n)) steps me decide kar le", aur DSPACE(f)\mathrm{DSPACE}(f) space ke liye same baat.

In choti bricks se badi classes bante hain: P=kDTIME(nk)\mathsf{P}=\bigcup_k \mathrm{DTIME}(n^k) — yani polynomial time, jise "efficient" maana jaata hai (kyunki polynomial ke andar polynomial daalo toh phir bhi polynomial rehta hai, robust hai). NP\mathsf{NP} matlab guess-and-verify in polynomial time. Ek bahut zaroori derivation: head ek step me ek hi cell hilta hai, isliye time ff ka matlab space f\le f — yani PPSPACE\mathsf{P}\subseteq\mathsf{PSPACE}. Aur agar space kam hai toh configurations bhi limited (2O(f)2^{O(f)}), aur halting machine koi configuration repeat nahi kar sakti, isliye time bhi 2O(f)2^{O(f)} tak hi — bas isi se poori chain ban jaati hai: LNLPNPPSPACEEXP\mathsf{L}\subseteq\mathsf{NL}\subseteq\mathsf{P}\subseteq\mathsf{NP}\subseteq\mathsf{PSPACE}\subseteq\mathsf{EXP}.

Yeh matter kyun karta hai? Kyunki interview aur GATE dono me yahi geography puchi jaati hai. Yaad rakho do galtiyan: (1) space time se chhota hota hai inclusion me, ulta nahi — reuse ke chakkar me confuse mat hona; (2) PNP\mathsf{P}\subseteq\mathsf{NP} toh pakka hai par strict hai ya nahi yeh aaj tak koi nahi jaanta — yahi famous P\mathsf{P} vs NP\mathsf{NP} million-dollar sawaal hai. Lekin PEXP\mathsf{P}\ne\mathsf{EXP} proved

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections