Quantum computers break factoring, but probably not NP. Run Shor’s period finding and Grover’s search, and see why a square-root speed-up is all unstructured search allows
A quantum computer is not a machine that tries every answer at once. It does break factoring, and with it most of today’s public-key cryptography. But for the NP-complete problems, the best anyone knows how to do is turn 2n steps into the square root of 2n, and a theorem says that blind search cannot do better. Everything on this page is a classical simulation of a small quantum system, which is exponentially expensive, and that expense is the point.
Press Reset, then Step, to watch the two reflections that make one iteration, and keep stepping past the best count to see the success probability fall again. Then switch the hidden item for a 3-SAT formula.
Indigo bars: the amplitude of each item, above or below zero; amber: the marked item; dashed: the mean amplitude. The chance of measuring an item is the square of its amplitude. When there are more items than pixels, each column stands for several. Rose strip: the boxes opened by a classical searcher who looks at one box per oracle call, in a random order. Lime arrow: the last measurement. This is a classical simulation storing all 2n amplitudes, which is why it stops at 10 qubits; a quantum computer would hold them in n qubits.
A quantum state over N items is a list of N amplitudes whose squares add up to 1; measuring it returns item i with probability equal to the square of its amplitude, and the rest of the state is gone. Amplitudes can be negative, and that is the whole resource: contributions can cancel. One Grover iteration is two reflections. The oracle negates the amplitude of every marked item. The diffusion step replaces each amplitude a by 2m − a, where m is the mean. In the plane spanned by “all marked items” and “all unmarked items”, two reflections make a rotation, by the angle 2θ where sin θ = √(M/N) for M marked items among N. After k iterations the chance of success is exactly sin²((2k + 1)θ), which is the curve in the demo, and the simulation matches it to twelve decimal places.
Lov Grover found the algorithm in 1996: unstructured search with about (π/4)√N oracle calls, where a classical search needs about N/2 on average. Stopping at ⌊π/(4θ)⌋ iterations gives success probability at least 1 − M/N. Charles Bennett, Ethan Bernstein, Gilles Brassard and Umesh Vazirani had already proved, in a paper published in 1997 and written before Grover’s algorithm was announced, that no quantum algorithm can search a black box in fewer than on the order of √N queries. Grover’s algorithm is optimal.
So a quantum computer that treats an NP-complete problem as a black box, asking only “does this assignment work?”, needs about 2n/2 steps: a quadratic speed-up, still exponential. Whether a quantum algorithm could exploit the structure of satisfiability to do fundamentally better is open, as P versus NP is. Most researchers believe that NP is not contained in BQP, the class of problems quantum computers solve efficiently, but nobody has proved it. The square-root trick does apply more widely than to blind search, including to randomised classical algorithms, and the result is still exponential.
The popular picture of “trying every answer in parallel” explains none of this. A superposition over all answers is easy to make, and measuring it gives one answer chosen at random, which is no better than guessing. The art of a quantum algorithm is arranging the interference so that the amplitudes of wrong answers cancel and those of right answers add. For search, the cancellation can only be arranged at the rate of one small rotation per question. See also the Computational Complexity module for classical satisfiability solvers.
Pick a number N and a base a, then go through the three stages: the repeating pattern, the simulated quantum measurement, and the fractions that turn a measurement into factors. Run the quantum part 200 times, and try a red base to see the algorithm fail honestly.
Stage 1: amber dots are the first period, green dots the returns to 1. Stage 2: indigo is the simulated quantum state (the comb, then the chance of each outcome), lime is what measurements returned. The quantum part is simulated by a classical Fourier transform over all Q = 512 amplitudes, which is exactly the exponential cost a quantum computer avoids. Numbers this small can be factored in your head; the real target has hundreds of digits, where the register would need thousands of reliable qubits.
These are formulas, not measurements: √N for trial division, the heuristic running time of the general number field sieve with its lower-order term dropped, and the cube of the number of bits for Shor’s algorithm with the constant taken as 1. Read them for their shapes. The classical curves are the best methods known, not proved limits: nobody has shown that factoring is hard for classical computers.
If r is the period of the powers of a modulo N and r is even, then ar − 1 = (ar/2 − 1)(ar/2 + 1) is a multiple of N. Unless ar/2 ≡ −1, neither factor is a multiple of N on its own, so each shares a proper factor with N, and Euclid’s algorithm finds it. For N a product of two distinct odd primes, at least half of the bases coprime to N work. The whole difficulty is finding r, which can be nearly as large as N.
The quantum part finds it. A register of Q ≥ N² values is put in uniform superposition, ax mod N is computed into a second register, and what remains in the first is periodic with period r. The quantum Fourier transform, which takes on the order of (log Q)² elementary operations, concentrates the amplitude near multiples of Q/r. A measurement y then satisfies |y/Q − j/r| ≤ 1/(2Q) with probability at least about 40%, and because Q ≥ N² the fraction j/r is the unique fraction with denominator below N that close to y/Q, so the continued-fraction expansion finds it. If j and r share a factor, the denominator is only a divisor of r; the demo tries a few small multiples, and otherwise one simply runs again.
Peter Shor published the algorithm in 1994: factoring and discrete logarithms in polynomial time on a quantum computer, so both are in BQP. In principle this breaks RSA, Diffie–Hellman and elliptic-curve cryptography. It does not touch the NP-complete problems. Factoring has special algebraic structure, the periodicity used here, and it sits in NP ∩ co-NP, where no NP-complete problem can be unless NP = co-NP. Nor is factoring proved hard classically: the curves in the chart are the best algorithms known, not lower bounds.
The simulation here costs time exponential in the number of qubits. As of this writing, machines large and reliable enough to threaten the key sizes in use do not exist. The response has not waited for them: in 2024 the United States National Institute of Standards and Technology issued new public-key standards, most of them based on lattice problems, which are believed (not proved) to be hard for quantum computers too. See also: Between and Beyond, for factoring’s place between P and the NP-complete problems.
Tap the regions and dots of the map to see what is proved and what is only believed. Then choose a task and a machine speed in the calculator, and compare RSA with 3-SAT at n = 300.
Map: tap a region or a dot. Nesting is drawn only where a containment is proved; the dashed indigo outline is BQP, whose position against NP nobody knows; dots are particular problems, placed where they are known or believed to lie. Calculator: rose is classical brute force, amber the best classical method known, indigo a Grover-style quantum search, sky Shor’s algorithm. It counts abstract operations from the scaling formulas and gives the quantum computer the same speed as the classical one with no error-correction overhead. Real quantum operations are far slower and costlier, so the quantum bars are optimistic. The time axis stops at 1040 seconds; an arrowhead means the bar runs off it.
BQP is the class of problems solvable in polynomial time by a quantum computer that errs with probability at most 1/3. Ethan Bernstein and Umesh Vazirani defined it in 1993 and proved that BPP ⊆ BQP ⊆ PSPACE. The upper bound matters: a quantum computer computes nothing that a classical computer cannot. The simulations on this page are the proof in miniature. They are slow, and they are correct.
Because P ⊆ BQP ⊆ PSPACE, a proof that BQP is strictly larger than P would also prove P ≠ PSPACE, which nobody can do. So quantum advantage itself is conditional: it rests on the belief that problems such as factoring have no fast classical algorithm. The strongest unconditional results are about black boxes: Grover’s speed-up and its matching lower bound, and the oracle of Ran Raz and Avishay Tal (2018) relative to which BQP is not inside the polynomial hierarchy. As the lesson on barriers explains, an oracle result is evidence and not a proof about the real classes. See also: The Barriers.
Some claims need careful reading. The sampling experiments reported as “quantum supremacy”, from 2019 on, concern contrived sampling tasks chosen to be hard to simulate; they are not NP problems, and checking their outputs is itself costly. Adiabatic and annealing devices have not shown exponential speed-ups on NP-complete problems. And the calculator above counts abstract operations: fault-tolerant quantum operations are far slower and costlier than classical ones.
What a working large-scale quantum computer would overturn is the extended Church–Turing thesis: the claim that every physically reasonable model of computation can be simulated by a Turing machine with only polynomial overhead. The original Church–Turing thesis, about what can be computed at all, would stand. And the question of this module would stand too: whether P = NP is a question about classical machines, and neither answer is settled by building a quantum one.
Spot a mistake or have an idea?