Polynomial Time and the Class P
Context: FIT2014_MOC · decidability is not enough — decidable says a computer can answer, this note asks whether it can answer before the sun dies; refines the tier regular ⊊ context-free ⊊ decidable by inserting
Quick Revision
- 🎯 Objective: ➔ is polynomial time iff for some fixed ➔ decided by some polynomial-time TM, the first formal definition of “efficiently solvable”.
- 📦 Core Components: time complexity ➔ worst case over inputs of length | polynomial slowdown ➔ why is model-independent | membership ➔ exhibit an algorithm and bound its steps.
- ⚡ Key Constraint: is fixed and input-independent — and are not polynomial; and is undefined unless is a decider, so a recogniser that loops has no time complexity at all.
📝 How It Works
1. Time complexity of a Turing machine
- Per-input cost ➔ the number of steps M takes on input until it halts — one step one transition, not one “operation”.
- The complexity function ➔ , a function of ➔ worst case, never average, and maximised over the finitely many inputs of each length.
- Definedness precondition ➔ the max exists only if halts on every input, i.e. is a decider ().
- Lecture’s three calibration examples ➔ strings ending in ➔ (sweep right to the blank, step back once) | palindromes ➔ (match-and-erase from both ends) | ➔ .
- Every regular language is in ➔ the FA to TM construction of Lecture 18 reads each letter once and never returns ⟹ .
2. The model dependence — and why it evaporates
- Details that move the constant ➔ number of tape symbols · tape infinite in one or both directions · number of tapes · dimensionality of the tape (1-D, 2-D, …) · whether “stay still” is a legal move.
- Why a fixed threshold fails ➔ declaring “efficient at most steps” is arbitrary, ties the definition to one machine model, and decays as hardware improves ⟹ the class must be closed under the differences above, and only the polynomial family is.
- Continuity with FIT1008/FIT1045 ➔ the complexity you already compute for programs also assumed a machine model, usually implicitly; is the version that stops depending on it (see Algorithmic Complexity).
3. Polynomial vs exponential — the growth gap
| If you… | time | exponential time |
|---|---|---|
| grow input by a fixed amount () | time grows by an additive | time grows by a fixed multiplicative factor |
| grow input by a fixed factor () | time | time raised to the power |
| double the machine’s speed | feasible input size fixed factor | feasible input size fixed amount |
| need inputs twice today’s size | wait years for hardware | wait your current input size |
When It Flips: the last two rows are the real argument — under Moore's Law a polynomial algorithm inherits hardware progress ( doublings years buys a doubling of ), an exponential one converts the whole of it into on the input size. Faster machines rescue polynomials, never exponentials.
4. The class
A language is polynomial-time decidable if some polynomial-time TM decides it. is the class of all such languages — historically the first, and still the default, formalisation of tractable.
- The power is fixed, the machine is not ➔ different members of have wildly different ; what matters is only that some fixed bounds the given machine.
- History ➔ Alan Cobham (1965), Jack Edmonds (1965), Michael Rabin (1966).
- Proving membership ➔ give an algorithm and bound its step count by a polynomial; the bound may be loose, since only the existence of some matters.
🧮 Proof Blueprint — is model-independent
Theorem. If can simulate with polynomial slowdown (a computation of taking time costs at most ), and is polynomial time, then simulates in polynomial time. Hence decidable in polynomial time on decidable in polynomial time on .
Strategy ➔ compose the two polynomial bounds and read off that a polynomial of a polynomial is a polynomial.
Derivation
Let be the time complexity of , so for some fixed and all sufficiently large . Then the time needs to simulate on an input of size is
- Key move: and are constants, so their product is a constant. The argument dies instantly if either exponent is allowed to depend on — which is exactly why “polynomial” must mean fixed power.
- Why it settles the definition: virtually any two “reasonable” computers simulate each other with at most polynomial slowdown, so is the same class whether defined over a one-tape TM, a laptop, or a supercomputer. This mirrors the history of decidability: many models, one class.
📚 Members of
| Family | Languages in | Certifying algorithm |
|---|---|---|
| Words | strings ending in · palindromes · · pairs in lexicographic order · matching parentheses | single or double sweep of the tape |
| Language classes | every regular language · every context-free language · | FA TM sweep; CYK at |
| Numbers | coprime pairs · square numbers · PRIMES (Agrawal–Kayal–Saxena, Annals of Mathematics, 2004) · invertible matrices | Euclidean Algorithm; AKS; Gaussian elimination |
| Graphs | trees · balanced binary trees · has an – path of length · regular graphs · 2-colourable graphs · Eulerian graphs · planar graphs (advanced) | search / degree counting / bipartiteness test |
| Logic | 2-SAT — satisfiable CNF with exactly two literals per clause | (slide’s challenge; algorithm not given) |
- Where the tiers now sit ➔ regular context-free decidable, each containment proper with a named witness: separates the first, and 2-SAT the second, and the time-bounded Halting Problem, RegExp equivalence, generalised Chess and generalised Go the third.
- 2-SAT vocabulary ➔ a truth assignment is a function ; an expression is satisfiable iff some assignment makes it True. For , gives False, but gives True ⟹ satisfiable. One bad assignment proves nothing.
⚠️ Common Mistakes
- 💡 Letting the exponent float ➔ ” for some ” quantifies once per machine, before the input is seen. has a growing exponent and is not polynomial.
- 💡 Computing for a non-decider ➔ no halting guarantee, no maximum, no time complexity. Establish “decider” before quoting a bound.
- 💡 Confusing “in ” with “fast” ➔ is in and useless in practice; is a robustness-driven abstraction, not a performance promise.
- 💡 Testing one truth assignment ➔ satisfiability is an claim (Quantifiers (Existential and Universal)). One assignment giving False refutes nothing; one giving True settles it.
- 💡 Quoting the model ➔ never write “in on a two-tape TM” — the slowdown theorem is precisely what makes the qualifier meaningless.
🧠 Active Recall
Why is the class defined by polynomial time rather than by an explicit threshold such as ?
Answer
- Short answer: because the polynomials are the smallest natural family closed under the differences between machine models — an explicit threshold would make “efficient” depend on tape count, alphabet size, and the calendar.
- Why: Polynomial slowdown composes ➔ if simulates in and then the total is , still polynomial because is a constant. Every reasonable model simulates every other with at most polynomial slowdown ⟹ is invariant, exactly as the class of decidable languages is invariant across models.
A colleague claims palindromes shows time complexity is a property of the language. Where is the error?
Answer
- Short answer: is a property of a machine, not a language; is what that TM costs. A language’s standing is the existential claim “some decider runs in “.
- Why: Different deciders, different bounds ➔ a two-tape machine decides palindromes in , the one-tape machine in ; both put the language in . Membership of therefore needs only one witnessing machine, and a slow decider never proves a language is outside .