4.6.22 · D3Theory of Computation

Worked examples — P — polynomial time

2,667 words12 min readBack to topic

The scenario matrix

Here is every kind of situation a "is it in P?" question can throw at you. Each column is a trap or a case you must be able to handle. The worked examples below are labelled with the cell they hit.

Cell Case class The question it tests Covered by
C1 Clean poly (small exponent) Count steps, get -ish, done Ex 1
C2 "Value vs length" trap Time looks small but is exponential in bits Ex 2
C3 Ugly-but-still-poly () Big exponent — still in P? Ex 3
C4 Nested/composed subroutines poly-inside-poly stays poly Ex 4
C5 Degenerate / zero / empty input , empty graph, single vertex Ex 5
C6 Limiting behaviour () Which term wins? does it stay poly forever? Ex 6
C7 Real-world word problem Translate a story into a step-count Ex 7
C8 Exam twist: "reduces to X" Poly reduction preserves P-membership Ex 8
C9 The fake-poly exponential , — poly or not? Ex 9

We now walk all nine.


This is the template: count → bound → declare polynomial. Every other example bends this template.


Figure — P — polynomial time

Look at the figure: the teal polynomial curve is visibly crushed by the orange once passes the crossover. That crossover is exactly why "value looks small" lies to you.


The lesson: P is a boundary of principle, not a promise of speed.


This is the reason polynomials were chosen as the feasibility line — the family survives being stacked on itself.


Takeaway: always poke and . A class definition that broke on empty input would be worthless — P doesn't.





Figure — P — polynomial time

The figure ranks all the growth families we met — poly (teal), the impostors (plum), the true exponential (orange) — so you can see the impostors sit above every polynomial forever.


The matrix, filled in

Active Recall

Recall Test yourself before moving on

Why does trial division fail as a P-proof? ::: Its step-count is exponential in the bit-length (Ex 2, Ex 6). A loop of calls a subroutine costing — total class? ::: , polynomial; nested repetition multiplies, exponents add (Ex 4). Is in P? ::: Yes — the exponent is a fixed constant, so it is a genuine polynomial (Ex 3). Is in P by that runtime? ::: No — the exponent grows with , so it is super-polynomial (Ex 9). Does the bound survive an empty graph? ::: Yes — constant setup is a degree-0 polynomial; both yes and no branches halt in bounded time (Ex 5).

Connections

  • Parent: P — polynomial time
  • Time complexity & Big-O
  • Polynomial-time reductions
  • NP-complete problems
  • TIME complexity classes
  • Cobham–Edmonds thesis