Why complexity theory belongs in an algorithms course
Every quantum algorithm in this course comes with a claim about speed, and those claims differ enormously in strength. Some are theorems about a restricted model, some rest on the belief that a classical problem is hard, and some are numerical observations on small instances. This lesson gives you the vocabulary to tell them apart and a habit of asking what exactly is being compared.
Complexity classes in brief
A decision problem asks a yes/no question about an input of bits. Three classes matter here.
- P: problems a deterministic classical algorithm solves in time polynomial in .
- BPP: problems a randomised classical algorithm solves in polynomial time with error probability at most on every input. Repeating and taking a majority vote drives the error down exponentially, so the constant is arbitrary.
- BQP: problems solved with error at most by a uniform family of quantum circuits of polynomial size, measured at the end. "Uniform" means a classical computer can write down the circuit for size in polynomial time, which rules out hiding the answer in the circuit design.
The known relationships are
Bernstein and Vazirani defined BQP and showed (Bernstein and Vazirani 1997); Adleman, DeMarrais and Huang tightened the upper bound to PP (Adleman, DeMarrais and Huang 1997). The inclusion holds because a quantum computer can simulate classical randomness. The PSPACE bound holds because the amplitude of an outcome is a sum over exponentially many computational paths, which a classical machine can add up with polynomial memory, one path at a time; the PP bound refines the same path-sum idea.
What is not known matters more. Nobody has proved ; doing so would also separate P from PSPACE, a famous open problem. So every claimed exponential quantum speed-up for a decision problem rests on a conjecture about classical hardness. Factoring is in BQP by Shor's algorithm (Shor 1997), but factoring is not known to be outside BPP, or even outside P; the best known classical algorithms are super-polynomial. NP-complete problems are widely believed not to be in BQP, and the BBBV bound from the Grover lesson is evidence for that belief, not a proof.
Query complexity versus circuit complexity
In the query model the input is hidden behind an oracle and we count oracle calls. In the circuit model we count all gates. The two answer different questions.
Query complexity is where quantum lower bounds are actually provable. BBBV shows that unstructured search needs queries (BBBV 1997), and oracle problems exist for which quantum algorithms need super-polynomially (for some problems, exponentially) fewer queries than any classical algorithm; Bernstein and Vazirani gave a super-polynomial separation of this kind in the same paper. These are theorems.
They do not automatically say anything about running time on a real problem, for two reasons.
- The oracle must be built. In an application, the oracle is a circuit that evaluates a function, and each query costs its gate count. A -query algorithm whose oracle needs gates is a -gate algorithm.
- Real problems have structure. A query lower bound assumes the algorithm learns about the input only through the oracle. A SAT formula is not a black box: classical SAT solvers exploit its clauses and routinely beat brute force by enormous factors, and Grover search over assignments competes against them, not against exhaustive search.
Circuit lower bounds, by contrast, are almost entirely out of reach: we cannot even prove that NP problems need super-linear classical circuits. That is why "quantum advantage" for concrete problems is always stated relative to the best known classical algorithm.
The main speed-ups and their fine print
| Algorithm | Speed-up and status | Conditions that must hold |
|---|---|---|
| Shor: factoring, discrete logarithms | super-polynomial over the best known classical algorithms; classical hardness is a conjecture | a fault-tolerant machine large enough for modular exponentiation |
| Grover, amplitude amplification | quadratic in queries; optimal in the query model (theorem) | an efficient oracle; a classical competitor that cannot exploit structure; error-correction overhead small enough |
| HHL for linear systems | exponential in under strong conditions | sparse, well-conditioned matrix; efficient preparation of ; output is a quantum state, so only expectation values are cheap |
| Simulating quantum dynamics | polynomial quantum algorithms for local Hamiltonians; no efficient classical algorithm known in general | a Hamiltonian with local or sparse structure; a question answered by measurements of the evolved state |
A few remarks on the rows.
Shor. The speed-up is real in the sense that no classical polynomial-time algorithm is known after decades of effort, but it is not proven. The resources needed to run it at a cryptographically relevant size are the subject of the resource-estimation lesson.
Grover. The quadratic improvement is proven but fragile in practice: on an error-corrected computer each logical operation is far slower than a classical operation. Babbush and coauthors analysed this trade-off with concrete surface-code constructions and concluded that quadratic speed-ups are unlikely to give a runtime advantage on early fault-tolerant devices, while higher polynomial speed-ups look more promising (Babbush et al. 2021). The exercise reproduces the shape of that argument with deliberately simple assumptions.
HHL. The algorithm of Harrow, Hassidim and Lloyd prepares a state proportional to in time polylogarithmic in the dimension and polynomial in the condition number and the inverse precision (Harrow, Hassidim and Lloyd 2009). It does not output the vector : reading all entries would cost order . Aaronson's commentary lists the caveats (input loading, condition number, sparsity, output access) that must all be satisfied before an exponential advantage survives (Aaronson 2015).
Simulation. Lloyd showed that a quantum computer can efficiently simulate the time evolution of local Hamiltonians (Lloyd 1996). No efficient classical algorithm is known for general quantum dynamics, which makes this the most widely expected application. "Known" is again doing work here: for specific Hamiltonians, classical methods (tensor networks, quantum Monte Carlo) can be very effective.
Dequantization
Some proposed exponential speed-ups, notably for recommendation systems and low-rank linear algebra, assumed that the quantum algorithm can sample from its input data cheaply. Tang showed that a classical algorithm with comparable sampling access to the same data can solve the recommendation problem in time polylogarithmic in the dimension, removing the exponential gap (Tang 2019). Chia and coauthors extended this to a general framework for low-rank matrix problems (Chia et al. 2020). The classical algorithms are polynomially slower, often by large polynomials, so a polynomial quantum advantage may remain. Dequantization does not show that quantum machine learning is useless; it shows that an exponential speed-up claim must compare against classical algorithms given the same input model.
How to read an advantage claim
Ask these questions in order.
- What is counted? Queries, gates, circuit depth, wall-clock time, energy? A query advantage is not a time advantage until the oracle is costed.
- Against which classical method? The best known algorithm for that problem, or a convenient one? Brute-force search is almost never the right baseline.
- What are the input and output models? Is the data loaded into amplitudes for free? Is the output a quantum state when the user needs numbers?
- What is proven? Separate theorems (query bounds, complexity inclusions), conjectures (classical hardness of factoring) and empirical observations (a heuristic worked on these instances).
- Which overheads are included? Error correction can multiply qubit counts by a thousand or more and slow each logical operation by orders of magnitude.
- At what size does it matter? An asymptotic advantage can start beyond any practical size.
Worked example: when would Grover win?
Consider unstructured search with one marked item and an oracle that is equally cheap to evaluate classically and quantumly in gates. Let one classical query take seconds and one Grover iteration (oracle plus diffusion, on error-corrected hardware) take seconds. Classical random search needs on average queries and Grover needs about iterations, so the times are and . Setting them equal gives the crossover
The timing values below are illustrative assumptions chosen to show how the answer scales; they are not measurements of any device. Take .
| assumed | crossover size | run time at crossover |
|---|---|---|
| min |
Two features generalise. The break-even time grows with the square of the quantum step time, so slow logical operations hurt quadratically. And beyond the crossover the advantage grows slowly: at the classical search takes and Grover takes . With , a tenfold saving () means about 3.4 hours of quantum computing against 34 hours classically. Parallelism makes it worse: splitting the search over classical machines divides by , while splitting it over quantum machines divides only by . In the exercise you show that this moves up by a factor while leaving the break-even time unchanged.
Query counts alone look very different. For , the exercise gives an expected 805 oracle calls for Grover search (including a final check and the rare retry), against 524,288.5 for classical random search: a factor of about 650. Whether that becomes a saving in time depends entirely on .
Exercise: query counts and a crossover
In query-count-crossover you compute expected classical and Grover query counts, wall-clock
times under stated assumptions, and the closed-form crossover. The checks compare your classical
expectation with a seeded Monte Carlo simulation, check that Grover's expected queries approach
, compare your closed-form crossover with an independent bisection, and confirm
the scaling with parallelism and with .
Common mistakes
- Equating a query speed-up with a time speed-up. The oracle's gate count and the speed of logical gates decide the outcome.
- Using exhaustive search as the classical baseline when the problem has exploitable structure.
- Reading "exponential speed-up" without its conditions. For HHL-type algorithms, check input loading, conditioning, sparsity and output access.
- Treating dequantization as a proof that quantum methods are useless. It removes some exponential gaps; polynomial ones can remain.
- Treating an assumption as a fact. Every timing number in a crossover estimate must be labelled with where it came from.
Summary
is what we know; that BQP is strictly larger than BPP is a conjecture. Quantum lower bounds are provable in the query model, but turning a query advantage into a time advantage needs an efficient oracle and an honest classical baseline. Shor's speed-up rests on the presumed classical hardness of factoring; Grover's is proven but quadratic and sensitive to error-correction overhead; HHL's exponential speed-up needs a list of conditions on input and output; simulation of quantum dynamics is the most broadly expected advantage. A simple crossover model shows that with slow logical operations, Grover search pays off only for very large problems and long runs. The lessons that follow apply the same scrutiny to QAOA, quantum machine learning and fault-tolerant resource estimates.