Qubits, superposition and the circuit model
A quantum computer operates on qubits — two-level systems that, unlike classical bits, can exist in arbitrary superpositions |ψ⟩ = α|0⟩ + β|1⟩ with |α|² + |β|² = 1. An n-qubit register lives in a Hilbert space of 2ⁿ complex amplitudes: 3 qubits already span 8 simultaneous amplitudes. The Hadamard gate creates equal superposition, and the set {Hadamard, T, CNOT} is universal — any quantum computation can be built from just these three gates.
The algorithm: oracle plus diffusion
Lov Grover (1996) devised an algorithm to find a marked item in an unsorted database of N items, which classically requires O(N) queries on average. Grover's algorithm needs only O(√N):
1. Initialise: |ψ⟩ = H^⊗n |0⟩ⁿ (equal superposition of all N states)
2. Repeat ≈(π/4)·√N times:
a. Oracle: O|x⟩ = −|x⟩ if x matches, +|x⟩ otherwise
b. Diffusion: 2|ψ⟩⟨ψ| − I ("inversion about the mean")
3. Measure → obtains the marked item with probability ≥ 1 − ε
N = 2²⁰ ≈ 10⁶: classical avg 500,000 queries vs Grover ~785 queries
The geometric picture
Each Grover iteration rotates the state vector by a fixed angle 2θ toward the marked state, where sinθ = 1/√N. The optimal number of iterations is t = (π/4)·√N — overshoot past this point and the amplitude rotates back away from the target, so unlike classical search, more iterations are not always better. At N = 2⁵⁶ ≈ 7×10¹⁶, classical brute force needs about 10¹⁷ queries on average; Grover needs roughly 2×10⁸ — a difference of nine orders of magnitude.
Why it matters for cryptography
Grover's algorithm has a direct security implication for symmetric-key cryptography. A 128-bit key (AES-128) needs a classical brute-force search of 2¹²⁸ possibilities; Grover reduces that to about 2⁶⁴ quantum queries — effectively halving the security margin. NIST's response is straightforward: use AES-256 rather than AES-128 to maintain a genuine 128-bit level of security against quantum adversaries. Crucially, Grover's speedup is quadratic, not exponential like Shor's factoring algorithm — it cannot solve NP-complete problems in polynomial time, since the underlying search space is still exponential even after the square-root reduction.
Frequently asked questions
How does Grover's algorithm search faster than a classical computer?
It starts in an equal superposition of all N possible states, then repeats two operations roughly (π/4)·√N times: an oracle that phase-flips the amplitude of the marked item, and a diffusion step that performs "inversion about the mean", amplifying the marked amplitude while shrinking the others. After the optimal number of iterations, measuring the register returns the marked item with near-certainty — using only O(√N) oracle queries instead of the classical O(N).
Does Grover's algorithm break AES encryption?
It weakens but does not break symmetric encryption outright. Classical brute-force against AES-128 needs 2^128 queries; Grover reduces this to about 2^64 queries, roughly halving the effective key length. NIST's recommendation is to use AES-256 instead of AES-128, since 2^128 quantum queries against a 256-bit key remains computationally infeasible.
Why can't Grover's algorithm solve NP-complete problems efficiently?
Grover's speedup is quadratic, not exponential: it turns an O(N) unstructured search into O(√N). For NP-complete problems, the search space itself is typically exponential in the input size, so even a quadratic reduction of an exponential number still leaves an exponential number of queries — nowhere near the polynomial time needed to solve NP-complete problems efficiently.
Try it live
Everything above runs in your browser — open Grover's Search Algorithm and step through amplitude amplification on a 4-qubit register (N=16), watching the oracle and diffusion phases as a live histogram. Nothing is installed, nothing is uploaded.
▶ Open Grover's Search Algorithm simulation