Complexity Classes
Which problems are feasible: P, NP and PSPACE, what a certificate proves, how a reduction transfers hardness, and where computation is impossible. Interviewers probe it before you optimize anything.
part ofComputer science fundamentalsoverview, primer and where to startread it →on this pageshowhide
explore
- Deterministic Resource Bounds15 questions
- Polynomial Time and Encoding6 questions
- Logarithmic and Polynomial Space5 questions
- Inclusions and Separations4 questions
- Nondeterminism and Certificates20 questions
- Verifiers and Witnesses5 questions
- Co-NP and Disproofs5 questions
- P vs NP Consequences5 questions
- Randomized and Counting Models5 questions
- NP-Completeness19 questions
- Membership and Hardness5 questions
- Cook-Levin Theorem4 questions
- Satisfiability and Graph Problems5 questions
- Numeric and Packing Problems5 questions
- Reductions and Decidability14 questions
- Polynomial Mappings and Direction5 questions
- The Halting Problem5 questions
- Rice's Theorem4 questions
- Coping With Intractability20 questions
- Triaging an Unknown Problem5 questions
- Approximation Guarantees5 questions
- Fixed-Parameter Feasibility5 questions
- Exact Search and Heuristics5 questions
- Computer Scienceskillanchors this topic
- AI & Data Scientistrole
- Backend Developerrole
- Blockchain Developerrole
- Data Analystrole
- Data Engineerrole
- Forward Deployed Engineerrole
- Full Stack Developerrole
- Game Developerrole
- Java Backend Developerrole
- Kotlin Backend Developerrole
- Machine Learning Engineerrole
- Server-Side Game Developerrole
- Software Architectrole
questions
88 · 5 sectionsWhy does complexity theory draw the line for 'efficient' at polynomial running time rather than at a fixed step budget?
basics
~20 sPolynomial time is a claim about scaling, not about one machine. A polynomial bound survives a change of machine model and stays polynomial when routines call each other; a fixed step budget expires with the next hardware or the next larger input.
A colleague draws L inside P inside NP inside PSPACE inside EXPTIME and calls every step strict - which steps are actually proven?
basics
~20 sNone of those four adjacent steps is proven strict; each one is open. The proven separations skip levels: the time hierarchy theorem puts P strictly inside EXPTIME, which forces at least one step in between to be strict.
Why does logarithmic space, the class L, charge only a work tape and never the read-only input a machine scans?
basics
~20 sLogarithmic space counts only the read-write work tape. The input is already present, read-only and freely re-readable, so charging for it would put every problem at n cells and leave no sublinear class at all.
A nightly settlement job loops once per cent of each amount; why is that not polynomial time in the input length?
basics
~20 sInput length is the number of symbols needed to write the instance down, not the value it denotes. An amount of value V occupies about log2(V) bits, so a loop running V times runs exponentially many steps in that length.
Why can the same amount-scanning routine count as polynomial time under one input encoding and exponential under another?
basics
~20 sBecause the encoding fixes what the input length is. Written in tally marks, a value of one million is a million symbols long, so a per-unit scan is linear; written in any base of two or more it is twenty bits, and the same scan is exponential.
A teammate says a task is in NP and therefore needs exponential time. What does NP membership actually claim?
basics
~20 sNP membership claims only that a yes-answer has a short certificate a checker can validate in polynomial time. It says nothing about how long finding that answer takes, and it does not exclude an easy problem.
A policy checker reports that an access-rule table has no conflicting pair anywhere — why is that claim harder to certify than one conflict?
basics
~20 sA conflict has a short witness: two rules plus one request that matches both, re-checkable in polynomial time. Absence has no such witness — it is a claim about every possible request, and that asymmetry between existential and universal claims is what co-NP captures.
Why is it wrong to say that a problem being in NP means it takes exponential time to solve?
basics
~20 sNP is defined by cheap checking, not by expensive solving. Every polynomial-time problem is already inside NP, and for no NP-complete problem has anyone ever proven a superpolynomial lower bound; exponential is the best known cost, not a floor.
A randomized decision procedure is wrong either way with probability at most 1/3 per run; why does majority voting over independent repeats make it negligible?
basics
~20 sMajority voting over k independent runs drives a two-sided error of 1/3 down exponentially in k: the wrong verdict needs more than half the runs to fail at once, which a Chernoff bound makes vanishingly unlikely. Cost grows linearly, failure falls exponentially.
A primality screen may pass a composite but never rejects a prime; what does that one-sided error let you conclude from each verdict?
basics
~20 sA composite verdict is a proof and can be trusted outright; a prime verdict is only probable. One-sided error means the certainty lives on exactly one side, which is why repeating with fresh random bases drives the remaining doubt down multiplicatively.
Why can a conflict graph be checked for two-colourability in linear time when three-colourability is NP-complete?
basics
~20 sTwo colours leave no freedom: fix one vertex and propagation forces every other, so one traversal either succeeds or exposes an odd cycle. A third colour restores a choice at each vertex, and those choices interact globally.
Cook-Levin proved satisfiability NP-complete without reducing from an earlier complete problem - why was there no alternative?
basics
~20 sA hardness proof normally transfers hardness from a problem already known complete, and at the time none existed. Cook-Levin therefore argued about every problem in NP at once, encoding an arbitrary verifier's computation directly as a Boolean formula.
A reviewer calls a shift-assignment problem NP-hard; which problems show that is weaker than NP-complete?
basics
~20 sNP-hard only says everything in NP reduces into the problem; it does not place the problem in NP. Optimization phrasings, which are not decision problems, and the halting problem, which is undecidable, are NP-hard and outside NP.
A design document calls a shift-assignment feature NP-complete. What two obligations must that claim discharge?
basics
~20 sAn NP-completeness claim owes two proofs: membership, that a short certificate for a yes answer is checkable in polynomial time, and hardness, that an already-complete problem reduces into it. Proving only the second gives NP-hardness, not completeness.
Partition asks whether parcel weights split evenly between two trucks; why doesn't an O(n*T) table over totals put it in P?
basics
~10 sAn O(n*T) table is pseudo-polynomial: T is a numeric value carried by only about log T digits, so the table is exponential in the instance's written length, not polynomial in it.
Why can no tool flag exactly the programs that loop forever, however sophisticated its analysis becomes?
basics
~10 sDeciding whether an arbitrary program stops is undecidable, so no checker can be always-terminating, never-wrong and complete at once. Every real loop detector therefore misses cases, raises false alarms, or sometimes fails to answer.
How does assuming a perfect halting decider let you build a program that contradicts it?
basics
~20 sAssume a routine that always terminates and correctly reports whether any program halts on any input. Write a program that asks it about itself and then does the opposite. Running that program on its own text makes the routine wrong either way.
A teammate maps their scheduling task onto SAT and concludes the task is NP-hard, so what did that direction actually prove?
basics
~10 sThe opposite of the claim. Mapping your task into SAT shows the task is no harder than SAT, an upper bound. Hardness needs the reverse map: a known-hard problem translated into your task.
What must a polynomial-time many-one reduction from problem A to problem B guarantee about every instance it maps?
basics
~10 sA polynomial-time many-one reduction turns any instance of A into one instance of B using only polynomial work, and guarantees the answer survives the trip: yes maps to yes, and no maps to no.
A review gate counts a file's lines exactly but can only guess whether a function ever returns a negative number, so why?
basics
~20 sLine count is a syntactic property, readable from the text itself. Whether a function ever returns a negative number is a property of the function it computes, and Rice's theorem makes every nontrivial property of that kind undecidable.
An unfamiliar requirement is written in business language; how do you check whether it is a known hard problem in disguise?
basics
~20 sStrip the domain nouns and restate the requirement as objects, a relation between them, and an objective. That skeleton — cover everything, pick a subset under a budget, order with no repeats — is what you match against the known catalogue.
A probe-selection tool claims a proven 2-approximation for total probe cost — what exactly does that ratio promise about any single run?
basics
~20 sA 2-approximation promises that on every input the returned cost is at most twice the best possible cost. It is a proven worst-case ceiling on answer quality, not an average over inputs and not a statement about running time.
In a branch-and-bound search for a minimum-cost plan, what do the incumbent and the bounding function each do to let you skip a subtree?
basics
~20 sThe incumbent is the best complete plan found so far, and its cost is the cut-off. The bounding function computes an optimistic cost for everything still reachable in a subtree; if that is no better, the subtree is discarded unexplored.
Why does a solver costing 2^k times n stay workable as the graph grows, when n^k with the same conflict count k does not?
basics
~20 sThe exponent's home decides it. In 2^k times n only the small conflict count k sits in an exponent, so a bigger graph costs a linear factor more. In n^k the graph itself is raised to k, so growth is fatal.
What three feasibility verdicts can a triage of an unfamiliar task return, and what evidence does each one need?
basics
~20 sRoutine, hard, or impossible. Routine needs a named polynomial method that fits; hard needs a known NP-complete problem sitting inside the requirement; impossible needs the shape of a question about what an arbitrary program does at runtime.