Would a Quantum Computer Help?

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

Would a Quantum Computer Help?

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.

Grover’s Search

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.

> 99.9%
chance that a measurement now finds one of the marked items
4
oracle calls so far (one per iteration)
4 (≈ 4.4)
best iteration count, about (π/4)√N
16.5
boxes a classical searcher opens on average
This is the moment to measure: after 4 oracle calls the chance of success is > 99.9%, against 13% for a classical searcher with the same number of looks. Keep stepping to see what happens if you do not stop.

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.

Go deeper:A Square Root, and a Proof That It Is the Limit

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.

Shor’s Period Finding

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.

Number to factor, N
Base a: every number from 2 to N − 1 with no factor in common with N. Green bases lead to the factors; red ones do not.
r = 6
the period of the powers of 2 modulo 21
Q = 512
register size: 9 qubits, the least power of two that is at least N²
1 of 1
runs whose measurement gave back r (expected 81% of the time)
6 of 11
bases that lead to the factors of 21
Multiply by 2 over and over, keeping only the remainder on division by 21, and the values come back to 1 after r = 6 steps and repeat for ever. Knowing r is enough to factor N, as stage 3 shows. Here r was found by walking along the sequence, which for a number of hundreds of digits would take longer than the age of the universe. Finding the period is the one job handed to the quantum computer.

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.

1.8 × 10³⁰⁸
trial division: up to √N divisions
1.5 × 10³⁵
number field sieve, the best classical method known
8.6 × 10⁹
Shor’s algorithm: about (log₂ N)³ quantum operations

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.

Go deeper:Why Factoring Falls and What It Does Not Show

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.

What Quantum Changes

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.

PSPACEBQPNPco-NPPBPPfactoringNP-completebeyond NP (oracle)
BQP — open. Problems a quantum computer solves in polynomial time, with error at most 1/3 (Bernstein and Vazirani, 1993). Proved: BPP ⊆ BQP ⊆ PSPACE. Not proved: that BQP is any larger than P. How BQP sits against NP is unknown in both directions, which is why its outline is dashed: NP is not known to be inside BQP, and BQP is not known to be inside NP.
At 1.0 × 10⁹ operations a second, the best classical method known needs 4.9 × 10¹⁸ years to factor a 2,048-bit modulus, and Shor’s algorithm needs 8.6 seconds. This is the one place on the page where a quantum computer changes “never” into “soon”. A Grover-style search for a factor would still take 3.3 × 10¹³⁷ years: the gain comes from the periodic structure of the problem, not from being quantum as such.
1.8 × 10³⁰⁸
operations — classical brute force: trial division up to √N
1.5 × 10³⁵
operations — best known classical method: the number field sieve
1.1 × 10¹⁵⁴
operations — grover-style quantum search: square root of the brute-force count
8.6 × 10⁹
operations — shor’s algorithm: about (log₂ N)³ quantum operations

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.

Go deeper:BQP and the Limits of Quantum Speed-Up

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.

Key Takeaways

  • Grover’s algorithm searches N items with about (π/4)√N questions, and Bennett, Bernstein, Brassard and Vazirani proved that no quantum algorithm for black-box search can do better.
  • Shor’s algorithm factors in polynomial time by finding a period, a structure that factoring has and that no NP-complete problem is known to have.
  • BPP ⊆ BQP ⊆ PSPACE is proved; that NP-complete problems lie outside BQP is widely believed and unproved.
  • A square root of an exponential is still an exponential: at n = 300, 3-SAT is out of reach for every method known, quantum included.

Spot a mistake or have an idea?

Search