- Algorithms
- Also: Grover's search
Grover's Algorithm
A quantum search algorithm that finds a marked item in an unsorted database of N items in O(√N) queries, a quadratic speedup over any classical algorithm.
Grover’s algorithm, developed by Lov Grover in 1996, is the best quantum algorithm for searching an unsorted database. Given items with exactly one marked item, a classical algorithm requires queries on average. Grover’s algorithm finds the marked item in queries. For a database of one million entries, classical search needs up to 500,000 queries; Grover’s needs about 785.
This quadratic speedup is provably optimal: no quantum algorithm can do better for an unstructured search problem. It is impressive, but it is not the exponential speedup that makes Shor’s algorithm so threatening to cryptography.
The details
Grover’s algorithm operates in two repeating steps, run approximately times:
Step 1 - Oracle query: The oracle marks the target item by flipping its amplitude’s sign. If the target state is , the oracle applies for and leaves all other states unchanged. This is a phase kick: the amplitude goes from to .
Step 2 - Diffusion operator (inversion about the mean): The diffusion operator reflects all amplitudes about their mean value. Because the target’s amplitude was made negative by the oracle, it is below the mean. The reflection raises it above the mean and pushes all other amplitudes slightly downward.
After each iteration, the target’s amplitude grows by roughly and all others shrink. After iterations, the target amplitude is approximately 1 and measurement yields the correct answer with high probability.
The circuit structure:
|0...0⟩ ──[H⊗n]──[Oracle]──[Diffusion]──[Oracle]──[Diffusion]── ... ──[M]
where prepares the uniform superposition over all states, and the Diffusion operator is implemented as .
In Qiskit, a 2-qubit example searching for :
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h([0, 1]) # Uniform superposition
# Oracle: mark |11>
qc.cz(0, 1) # Flips phase of |11>
# Diffusion operator
qc.h([0, 1])
qc.x([0, 1])
qc.cz(0, 1)
qc.x([0, 1])
qc.h([0, 1])
qc.measure_all()
print(qc.draw())
# Running this should yield '11' with ~100% probability after 1 iteration
Why it matters for learners
Grover’s algorithm is the canonical example of quantum speedup through interference. The oracle step and diffusion step together implement a geometric rotation in the two-dimensional subspace spanned by the target state and the uniform superposition. The algorithm is essentially a quantum rotation that takes steps to reach the target, rather than the steps needed classically.
Beyond search, Grover’s algorithm serves as a subroutine in many other quantum algorithms. It can be used to speed up constraint satisfaction problems, optimization tasks, and even parts of other search procedures. Any problem that can be cast as “find an input satisfying some condition” can potentially benefit from a Grover speedup.
The quadratic speedup does have real-world implications for cryptography, even if it is less dramatic than Shor’s. Grover’s algorithm halves the effective key length of symmetric encryption: AES-128 provides roughly 64 bits of security against a quantum adversary with Grover’s algorithm. This is why NIST recommended 256-bit symmetric keys as a conservative post-quantum measure.
Common misconceptions
Misconception 1: Grover’s algorithm evaluates all N possibilities simultaneously. It does not work by parallel evaluation. The superposition explores all possibilities, but the oracle and diffusion steps iteratively rotate the quantum state toward the answer. If you measure too early or too late, you lose the speedup.
Misconception 2: Grover’s algorithm breaks AES encryption. It weakens symmetric encryption by providing a quadratic speedup on brute-force key search, but AES-256 remains secure against quantum adversaries because the resulting security level is still operations. Doubling the key length is the standard mitigation.
Misconception 3: The oracle is a free operation. In practice, implementing the oracle for a real problem (checking whether a candidate password hash matches, for example) requires a quantum circuit that evaluates the checking function. The cost of this circuit must be included when estimating the total quantum speedup. For many real problems, the oracle circuit is large enough that the advantage is offset.