Grover’s Algorithm

qc/algorithms

Solves unstructured search: given marking “solution” strings out of total, find one — classically this needs oracle calls on average, Grover’s needs only . Key insight: this is a proven-optimal quadratic speedup, not a shortcut to exponential — no sequence of unitaries interleaved with oracle calls can beat for a genuinely unstructured problem. Shor’s algorithm gets an exponential speedup instead, but only because factoring has extra algebraic structure (see The Quantum Algorithm Zoo) that Grover’s problem setup doesn’t have.

Oracle and phase kickback

The oracle acts as . Prepared against a target qubit in , this becomes a pure phase flip on solutions — exactly the phase-kickback trick: where .

The geometric picture

Split the search space into (uniform superposition over the non-solutions) and (uniform superposition over the solutions). The uniform starting state is with — a 2D problem living entirely in the plane. reflects the state across ; the diffusion operator reflects it back across . Two reflections compose into a rotation: one Grover iteration rotates the state by toward .

After iterations, with , and success probability . Since this is a rotation, overshooting past swings the probability back down — there’s a sharp optimum, not a monotonic improvement:

Circuit sketch

# one Grover iteration = oracle (phase flip on solutions) + diffusion
qc.append(oracle, range(n))                  # P_f: flips sign of solution states
qc.h(range(n))
qc.append(MCXGate(n-1), range(n))             # 2|0><0| - I, via multi-controlled phase
qc.h(range(n))
# repeat ~ (pi/4)*sqrt(N/M) times, then measure

Self-Check

  • Why is one Grover iteration a rotation rather than a monotonic increase toward the answer — what goes wrong if you run too many iterations?
  • How does phase kickback let a classical-looking oracle turn into a pure sign flip on solutions?
  • Why is provably optimal for unstructured search, while Shor’s algorithm still gets an exponential speedup on a different problem?