A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Time Complexity and the Class P

College Depth 81 in the knowledge graph I know this Set as goal
88topics build on this
482prerequisites beneath it
See this on the map →
Big-O Notation and Asymptotic AnalysisTuring Machines+3 moreComplexity Classes and the Complexity HierarchyDescriptive Complexity+10 more
complexity time-complexity polynomial-time P

Core Idea

The time complexity of a Turing machine on an input is the number of steps before it halts. DTIME(f(n)) is the class of languages decidable in O(f(n)) steps. The class P = ∪ₖ DTIME(nᵏ) captures 'efficiently solvable' problems — those with polynomial-time algorithms. P is robust to reasonable changes in the computational model (multi-tape TMs, random-access machines), making it the standard definition of tractability. The linear speedup theorem shows that constant factors in time bounds are irrelevant for class membership.

How It's Best Learned

Work through concrete examples of problems in P: sorting, graph reachability, primality testing (AKS). Then practice proving time bounds by counting TM steps or reasoning about algorithm complexity. Understand why polynomial vs. super-polynomial is the key dividing line rather than, say, linear vs. quadratic.

Common Misconceptions

Explainer

A Turing machine's time complexity on input x is simply the number of steps it takes before halting. To talk about complexity classes, we shift from individual inputs to languages: DTIME(f(n)) is the set of all languages that some deterministic Turing machine decides within O(f(n)) steps on every input of length n. This gives us a hierarchy — DTIME(n) ⊂ DTIME(n²) ⊂ DTIME(n³) ⊂ ... — and the class P is defined as the union of all these polynomial classes.

Why the union over *all* polynomials, rather than picking a specific one like quadratic? The answer is closure. If you run a cubic-time algorithm and then feed its output into a quadratic-time algorithm, the composition is still polynomial — but it might be degree 5 or 6, not 2 or 3. By defining P as the union over all finite-degree polynomials, we get a class that is closed under composition: any algorithm built from P-subroutines is itself in P. This composability is what makes P a natural unit for reasoning about tractable computation, not just an arbitrary choice.

The robustness of P is equally important. A polynomial-time algorithm on a single-tape Turing machine can be simulated on a multi-tape Turing machine, on a random-access machine, or on most other reasonable deterministic models, with at most polynomial overhead. The polynomial-versus-super-polynomial divide therefore does not depend on the specific machine model you choose — it is a property of the problem, not of the hardware abstraction. This is why P is used as the formal definition of "efficiently solvable" rather than something like "linear-tape TM in quadratic time."

The linear speedup theorem reinforces this picture: for any c > 1, any language in DTIME(f(n)) is also in DTIME(f(n)/c). This means constant factors in time bounds are irrelevant for class membership — they wash out under rescaling. What matters for P membership is whether the growth rate is bounded by some polynomial, not the specific constants or low-degree polynomial exponent involved.

One critical misconception to resist: P is not "efficiently solvable in practice." An algorithm running in n50 steps is in P but completely unusable. P is a theoretical lower bound on the possibility of tractability — if a problem is not in P, we have strong evidence it is fundamentally hard, regardless of hardware or clever implementation. If it is in P, we know tractability is possible in principle, but practical efficiency requires looking at specific exponents, average-case behavior, and constant factors that the asymptotic P definition deliberately ignores.

Practice Questions 3 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersDividing IntegersUnit RatesProportionsPercent ConceptConverting Between Fractions, Decimals, and PercentsOperations with Rational NumbersTwo-Step EquationsSolving Multi-Step EquationsEquations with Variables on Both SidesLiteral EquationsSlope-Intercept FormPoint-Slope FormWriting Linear EquationsParallel and Perpendicular Line SlopesGraphing Linear EquationsPiecewise FunctionsStep FunctionsComposition of FunctionsInverse FunctionsRadical Functions and GraphsRational ExponentsExponential Functions and GraphsLogarithms IntroductionBig-O Notation and Asymptotic AnalysisBreadth-First Search (BFS)Shortest Paths in Unweighted GraphsDijkstra's Shortest Path AlgorithmAlgorithm Analysis and Big-O NotationTuring MachinesTime Complexity and the Class P

Longest path: 82 steps · 482 total prerequisite topics

Prerequisites (5)

Leads To (12)