Skip to content

9.8

Grover's search algorithm

Two mirrors squeeze out a rotation: an oracle reflection plus an inversion-about-the-mean turns the state 2θ toward the target each round, hitting it in about (π/4)√N rounds — a quadratic speedup, proven to be the limit.

Recommended first

After this section you should be able to

  • Explain the Grover iteration with two-dimensional plane geometry: two reflections compose into one 2θ rotation
  • Hand-compute the complete N = 4 example and verify a 100% hit after one iteration
  • Derive the optimal iteration count ≈ (π/4)√N and explain why overshooting hurts
  • State the BBBV lower bound: √N is the limit of black-box search, not an engineering shortfall

Deutsch–Jozsa won on an artificial problem. This section tackles a problem everyone understands — finding a needle in a haystack — and this time the opponent is a genuine classical lower bound.

The problem at the door: N drawers, one key

N=2nN=2^n drawers, numbered 00 to N1N-1, exactly one of which (call it ww) hides the key. You have a black box ff: give it a number xx and it answers f(x)=1f(x)=1 if and only if x=wx=w. The only classical strategy is opening drawers: N/2N/2 on average, NN in the worst case, with no shortcut whatsoever — ff has no structure to exploit (this is not a sorted phone book; it is shuffled).

The quantum oracle copies last section’s phase kickback (the \ket{-} ancilla is now left implicit):

Ox=(1)f(x)xO=I2ww(9.8.1)O\ket{x}=(-1)^{f(x)}\ket{x} \qquad\Longleftrightarrow\qquad O=I-2\ket{w}\bra{w}\tag{9.8.1}

It does exactly one thing: flip the sign of the target branch.

Why one round of interference no longer suffices

Try copying DJ’s three moves: a row of HH‘s prepares the uniform superposition s=1Nxx\ket{s}=\frac{1}{\sqrt N}\sum_x\ket{x}, call the oracle once, then interfere. The trouble: the oracle flips the sign of only one of the 2n2^n amplitudes, and that perturbation affects the overall distribution at order O(1/N)O(1/\sqrt N) — one round of interference cannot wash it out, and a direct measurement still hits with probability about 1/N1/N. In DJ’s problem, “all the function values conspiring” produced a stark global signal; the search problem’s signal is thread-thin. The way out: stop hoping for a one-shot kill and let a small advantage snowball. Each round twists the amplitude pointing at the target a little larger; twist for N\sqrt N rounds. This “amplitude amplifier” is built from two mirrors.

The geometric picture: two mirrors = one rotation

All the action happens in a two-dimensional plane — the one spanned by the target state w\ket{w} and the uniform superposition s\ket{s}. Take the in-plane unit vector perpendicular to w\ket{w}, r=1N1xwx\ket{r}=\frac{1}{\sqrt{N-1}}\sum_{x\ne w}\ket{x} (the “uniform superposition of the other drawers”); then

s=cosθr+sinθw,sinθ=w|s=1N(9.8.2)\ket{s}=\cos\theta\,\ket{r}+\sin\theta\,\ket{w}, \qquad \sin\theta=\braket{w}{s}=\frac{1}{\sqrt N}\tag{9.8.2}

The initial state s\ket{s} sits only a small angle θ1/N\theta\approx1/\sqrt N above the “ground” r\ket{r}. The Grover iteration has two steps:

  1. The oracle OO: flips the sign of the w\ket{w} component = a reflection about r\ket{r} (mirror one);
  2. The diffusion operator D=2ssID=2\ket{s}\bra{s}-I: a reflection about s\ket{s} (mirror two).

Hand-compute N = 4: one iteration, a perfect hit

N=4N=4 (two qubits), target w=10w=10. Here sinθ=12\sin\theta=\tfrac12, θ=30\theta=30^\circ — not a “small” angle, which lets us hand-compute a whole round.

Step 0: s=12(00+01+10+11)\ket{s}=\tfrac12(\ket{00}+\ket{01}+\ket{10}+\ket{11}), all four amplitudes 0.50.5.

Step 1 (oracle): the target flips sign:

(12, 12, 12, 12)(9.8.8)\big(\tfrac12,\ \tfrac12,\ -\tfrac12,\ \tfrac12\big)\tag{9.8.8}

Step 2 (inversion about the mean): the mean is aˉ=0.5+0.50.5+0.54=14\bar a=\frac{0.5+0.5-0.5+0.5}{4}=\tfrac14. Each amplitude 2×14ax=12ax\mapsto 2\times\tfrac14-a_x=\tfrac12-a_x:

(0, 0, 1, 0)(9.8.9)\big(0,\ 0,\ 1,\ 0\big)\tag{9.8.9}

The state has become exactly 10\ket{10}. Measure: 100% hit, one query. Classically it takes 2.252.25 drawer-openings on average (3 in the worst case) to be sure. Geometric check: ϕ1=(2×1+1)×30=90\phi_1=(2\times1+1)\times30^\circ=90^\circ, dead-on target, to the degree.

Quadratic is the limit: the BBBV lower bound

Could a cleverer quantum algorithm manage logN\log N? No. The Bennett–Bernstein–Brassard–Vazirani theorem: any quantum algorithm for unstructured search needs at least Ω(N)\Omega(\sqrt N) oracle queries. The idea is worth remembering: each query perturbs the state by at most O(1/N)O(1/\sqrt N) (it moves the sign of only one branch), while pulling the final states for “the target is w1w_1” and “the target is w2w_2” apart to a distinguishable distance requires a cumulative perturbation of O(1)O(1) — divide, and Ω(N)\Omega(\sqrt N) falls out. Grover flies flush against the bound; even the constant π/4\pi/4 is optimal.

What comes next

The quadratic speedup already touches the ceiling of black-box search; for exponential speedup we must leave the black box behind and mine the problem’s internal structure. One problem’s structure happens to be exactly what quantum mechanics does best — periodicity: factoring large integers reduces to “finding the period of a function”, and finding periods is interference’s signature trade. Next section: Shor’s algorithm, and the sword it dangles over RSA.

Section 72 of 106 · use to turn the page