365 Architect

Grover's Algorithm

Definition

Grover's algorithm, discovered by Lov Grover in 1996, solves the unstructured search problem: given an oracle that recognises a marked state among NN unsorted items, find the marked state using O(N)O(\sqrt{N}) oracle queries. Classically, this requires O(N)O(N) queries in the worst case. Grover's algorithm is provably optimal — no quantum algorithm can beat O(N)O(\sqrt{N}) for unstructured search (Bennett et al., 1997).

The algorithm works by amplitude amplification: it iteratively flips the sign of the marked state's amplitude (via the oracle) and then inverts the amplitudes about the mean (via the Grover diffusion operator), causing the marked state's probability to grow quadratically faster than random chance.

Algorithm Outline

Setup

Let N=2nN = 2^n be the number of items, and define:

  • Oracle OO: A unitary that marks the target state ω\ket{\omega}:

    Ox={xif x=ωxotherwise\displaystyle O \ket{x} = \begin{cases} -\ket{x} & \text{if } x = \omega \\ \ket{x} & \text{otherwise} \end{cases}

    Implemented as a phase-flip on the target — often constructed from a classical Boolean function f(x)f(x) that returns 1 for the target and 0 otherwise.

  • Diffusion operator DD:

    D=2ψψI\displaystyle D = 2\ket{\psi}\bra{\psi} - I

    where ψ=Hn0n\ket{\psi} = H^{\otimes n} \ket{0}^{\otimes n} (the uniform superposition). DD inverts amplitudes about the mean.

Steps

  1. Initialise: Apply Hadamard gates to all nn qubits:

    ψ0=Hn0n=1Nx=0N1x\displaystyle \ket{\psi_0} = H^{\otimes n} \ket{0}^{\otimes n} = \frac{1}{\sqrt{N}} \sum_{x=0}^{N-1} \ket{x}

  2. Grover iteration (repeat π4N\approx \frac{\pi}{4}\sqrt{N} times):

    1. Apply oracle OO (flip sign of target amplitude).
    2. Apply diffusion operator DD (invert about the mean).
  3. Measure all qubits. The outcome is ω\omega with high probability (>1/2> 1/2 for optimal iteration count).

Iteration Count and Success Probability

The optimal number of iterations is:

R=π4NM\displaystyle R = \left\lfloor \frac{\pi}{4} \sqrt{\frac{N}{M}} \right\rceil

where MM is the number of marked items. After RR iterations, the success probability is sin2((2R+1)θ)\sin^2((2R+1)\theta) where θ=arcsin(M/N)\theta = \arcsin(\sqrt{M/N}).

NN N\sqrt{N} Iterations RR Success probability
4 2 1 100%
100 10 8 ~95%
10,000 100 79 ~99%
10610^6 1,000 785 ~100%

Circuit Diagram

|0⟩ — H —●———H─────────●———H──●——— ⋯ — M
|0⟩ — H —●———H─────────●———H──●——— ⋯ — M
|0⟩ — H —●———H─────────●———H──●——— ⋯ — M
         │         │         │
         │    ┌────┴────┐    │    ─
         │    │Diffusion│    │    ⋮
         │    └─────────┘    │
        Oracle            Oracle

Applications

Beyond database search, Grover's algorithm provides quadratic speedups for any problem reducible to unstructured search:

Application Classical complexity Quantum complexity Speedup factor (at N=106N=10^6)
Unstructured search O(N)O(N) O(N)O(\sqrt{N}) ×1,000
SAT (Boolean satisfiability) O(2n)O(2^n) O(2n/2)O(2^{n/2}) ×32,768 (at n=30n=30)
Collision finding (hash functions) O(2n/2)O(2^{n/2}) O(2n/3)O(2^{n/3}) ×32,768 (at n=60n=60)
Graph connectivity O(N+E)O(N + E) O(NE)O(\sqrt{NE}) ×1,000 (at N=106N=10^6)
Minimum finding O(N)O(N) O(N)O(\sqrt{N}) ×1,000
Mean/median estimation O(N)O(N) O(N)O(\sqrt{N}) ×1,000

Grover's Algorithm and Cryptography

Grover's algorithm halves the effective key length of symmetric ciphers:

Symmetric cipher Key length Effective security against Grover Required post-Grover key length
AES-128 128 bits 64 bits AES-256
AES-256 256 bits 128 bits AES-256 (already sufficient)
SHA-256 (collision) 256-bit output 85 bits (Grover + Brassard) SHA-512

Important caveat: Grover's algorithm requires a serial quantum circuit — each iteration depends on the previous one. Running 2642^{64} iterations for AES-128 on a single quantum processor would take an impractically long time. Parallelising Grover across many quantum processors reduces runtime but increases total physical qubit requirements by the parallelisation factor. Most estimates place the quantum resource needed to break AES-128 well beyond any plausible near-term hardware.

Amplitude Amplification (Generalised Grover)

Grover's algorithm is a special case of amplitude amplification — a framework that amplifies the amplitude of any "good" subspace. Given a unitary AA that prepares an initial state ψ=A0\ket{\psi} = A\ket{0} with probability pp of the good subspace, amplitude amplification finds a good state with O(1/p)O(1/\sqrt{p}) iterations.

This generalisation underpins:

  • Quantum counting: Estimate the number of solutions MM without enumerating them (uses quantum phase estimation + Grover iterations).
  • Quantum Monte Carlo: Quadratic speedup for estimating expectation values of random variables — O(1/ϵ)O(1/\epsilon) classical vs. O(1/ϵ)O(1/\epsilon) quantum.
  • Quantum optimisation: QAOA (Quantum Approximate Optimisation Algorithm) can be viewed as a continuous-time analogue of amplitude amplification.

Hardware Requirements

Grover's algorithm is shallower than Shor's — it requires roughly O(N)O(\sqrt{N}) sequential operations. For N=1012N = 10^{12} (40 qubits), that is ~10610^6 sequential gates. Current NISQ devices with 103\sim 10^{-3} per-gate error would produce essentially random results at this depth. Grover's algorithm therefore requires fault-tolerant qubits (error-corrected logical qubits) to reach useful problem sizes.

Resources and References

  • Grover, "A fast quantum mechanical algorithm for database search" (1996), STOC 1996, 212–219. [Original paper]
  • Bennett et al., "Strengths and weaknesses of quantum computing" (1997), SIAM J. Comput. 26, 1510–1523. [Optimality proof]
  • Brassard et al., "Quantum amplitude amplification and estimation" (2002), Quantum Computation and Quantum Information, 160–176.
  • Boyer et al., "Tight bounds on quantum searching" (1998), Fortschritte der Physik 46, 493–505.
  • Quantum circuit implementations: qiskit.org/textbook/ch-algorithms/grover.html — Qiskit textbook implementation.
Share on LinkedIn