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

Complexity Classes and the Complexity Hierarchy

Graduate Depth 96 in the knowledge graph ☐ I know this ☆ Set as goal
12topics build on this
584prerequisites beneath it
See this on the map →
Algorithm Analysis and Complexity ClassesSpace Complexity: PSPACE, L, and NL+5 more→→The P Versus NP Problem: Central Open QuestionThe Polynomial Hierarchy+1 more
complexity-classes hierarchy-theorem p-np-pspace

Core Idea

Complexity classes like P, NP, PSPACE, and EXPTIME group problems by the computational resources (time or space) required to solve them. The Hierarchy Theorem shows that these classes are strictly nested (e.g., P ⊆ NP ⊆ PSPACE ⊆ EXPTIME), with some containments proven and others (like P vs. NP) remaining famously open.

How It's Best Learned

Study the hierarchy theorem proofs to understand how resource bounds create proper inclusions. Visualize complexity classes as concentric circles to internalize nestings.

Common Misconceptions

Explainer

You already know how to measure time and space complexity: a problem's time complexity is roughly how many steps the best algorithm takes as input grows, expressed in big-O notation, and you've studied formal resource bounds like DTIME(f(n)) and DSPACE(f(n)). Complexity classes are simply the collections of all decision problems solvable within some bound. P is the class of problems solvable in polynomial time — O(nk) for some fixed k. NP is the class solvable in polynomial time on a nondeterministic Turing machine, equivalently, the class of problems whose solutions can be *verified* in polynomial time. Sorting is in P; given a proposed Hamiltonian cycle, you can check it in polynomial time, so the Hamiltonian cycle problem is in NP.

The hierarchy of classes P ⊆ NP ⊆ PSPACE ⊆ EXPTIME is an inclusion chain organized by resource. PSPACE groups problems solvable using polynomial *space* (but possibly exponential time), while EXPTIME groups those solvable in at most exponential time. The key insight is that using more resources can only help: a problem solvable in polynomial time is certainly solvable in polynomial space, because space can be reused across steps. This gives you the chain of inclusions for free — every problem in the smaller class is automatically a member of every larger class.

The Time Hierarchy Theorem and Space Hierarchy Theorem prove that the inclusions are *proper* when you jump by a sufficient factor. The Time Hierarchy Theorem says DTIME(n) ⊊ DTIME(n²) — there are problems solvable in quadratic time that cannot be solved in linear time. The proof is a diagonal argument in the tradition of Cantor and Turing: construct a machine that reads the description of other machines and deliberately differs from each in finite time, guaranteeing it computes a function none of them can. This gives you the guaranteed proper nesting: P ⊊ EXPTIME and PSPACE ⊊ EXPSPACE are both proven. The hierarchy theorems do *not*, however, resolve P vs. NP — diagonalization cannot separate classes that differ only by a polynomial factor without additional structure.

The famous open question — whether P = NP — asks if polynomial verifiability implies polynomial solvability. The question is hard precisely because every technique that would separate them (diagonalization, circuit lower bounds, natural proofs) has hit known barriers. What we *do* know is that if P ≠ NP, the class NP splits further: there are problems in NP that are neither in P nor NP-complete, a fact established by Ladner's theorem. The complexity hierarchy is thus not just a tower of inclusions but a landscape of problems clustered by difficulty, with P and EXPTIME as the two proven landmarks and NP as the central mystery between them.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Dividing Integers → Unit Rates → Proportions → Percent Concept → Converting Between Fractions, Decimals, and Percents → Operations with Rational Numbers → Two-Step Equations → Solving Multi-Step Equations → Equations with Variables on Both Sides → Angle Pairs: Complementary, Supplementary, and Vertical → Parallel Lines and Transversals → Corresponding Angles → Alternate Interior Angles → Triangle Angle Sum Theorem → Exterior Angle Theorem → Triangle Inequality Theorem → Similar Triangles: AA Similarity → Similar Triangles: SSS and SAS Similarity → Proportions in Similar Triangles → Right Triangle Trigonometry Introduction → Sine, Cosine, and Tangent Ratios → Trigonometric Ratios Review → Radian Measure → Converting Between Degrees and Radians → The Unit Circle → Graphing Sine and Cosine → Graphing Tangent and Reciprocal Trigonometric Functions → Derivatives of Trigonometric Functions → Antiderivatives → Indefinite Integrals → Basic Integration Rules → Riemann Sums → Definite Integral Definition → Probability Density Functions and Continuous Distributions → Cumulative Distribution Functions → Continuous Random Variables → Probability Density Functions → Expected Value → Weak Law of Large Numbers → Probability Axioms and Rules → Conditional Probability → Probabilistic Computation and BPP → BPP and Randomized Complexity → Randomized Complexity: RP, co-RP, and ZPP → Complexity Classes and the Complexity Hierarchy

Longest path: 97 steps · 584 total prerequisite topics

Prerequisites (7)

Leads To (3)