Explaining Grover's amplitude amplification
Grover's algorithm works by repeatedly rotating the state vector in a 2D space spanned by the marked target state and its orthogonal complement, using two reflections: the oracle flips the sign of the target state's amplitude, and the diffusion operator reflects about the uniform superposition. Each iteration rotates the state vector by about 2θ, where sin(θ) = 1/√N, so after roughly (π/4)√N iterations, the target amplitude—and thus the success probability—is maximized.
Grover's algorithm sits in the general pattern of “amplitude amplification”: you have a superposition in which the “good” basis states carry only a small amplitude, and you repeatedly apply a unitary that increases that amplitude while decreasing the amplitude on the “bad” states. After (O(1/\text{(initial amplitude)})) repetitions the overlap with the good subspace is close to 1.
For the unstructured search problem there are (N) basis states ({|0\rangle,\dots,|N-1\rangle}) and a Boolean function (f) marking the desired item(s), (f(x)=1) if (x) is a solution, (0) otherwise. The algorithm uses two simple unitary operators:
-
A phase oracle (O_f) that flips the sign of any marked basis vector. In its simplest form for a single marked item (|w\rangle),
[
O_f = I - 2,|w\rangle\langle w|,\qquad O_f|x\rangle = \begin{cases}-|x\rangle & x=w,\ |x\rangle & x\neq w.\end{cases}
]
More generally, (O_f = I-2\sum_{x:f(x)=1}|x\rangle\langle x|) implements (|x\rangle\mapsto(-1)^{f(x)}|x\rangle).
-
The diffusion, or “inversion about the mean”, operator
[
D = 2,|s\rangle\langle s| - I,
]
where (|s\rangle = \frac{1}{\sqrt{N}}\sum_{x=0}^{N-1}|x\rangle) is the uniform superposition. Acting on a general superposition (|\psi\rangle = \sum_x a_x|x\rangle), (D) leaves the average amplitude (\bar{a}=\frac{1}{N}\sum_x a_x) fixed and maps each (a_x) to (2\bar{a}-a_x), i.e. it reflects the amplitude distribution about its mean.
A single Grover “iteration” is the product (G = D,O_f). The power of the algorithm comes from the fact that, although (G) acts on an (N)–dimensional space, its nontrivial action is confined to the two‑dimensional subspace spanned by the marked state(s) and the superposition of unmarked states. For one marked state (|w\rangle), define an orthonormal basis
[
|w\rangle,\qquad |r\rangle = \frac{1}{\sqrt{N-1}}\sum_{x\neq w}|x\rangle,
]
so (|r\rangle) is the uniform superposition over all unmarked items. The initial state (|s\rangle) decomposes in this basis as
[
|s\rangle = \frac{1}{\sqrt{N}},|w\rangle + \sqrt{\frac{N-1}{N}},|r\rangle = \sin\theta,|w\rangle + \cos\theta,|r\rangle
]
with (\sin\theta = 1/\sqrt{N}) and (\cos\theta = \sqrt{1-1/N}).
Within the plane spanned by (|w\rangle) and (|r\rangle), both (O_f) and (D) are simple reflections:
-
(O_f) leaves (|r\rangle) invariant and sends (|w\rangle) to (-|w\rangle), so it is a reflection across the line along (|r\rangle).
-
(D) leaves (|s\rangle) invariant and flips the component orthogonal to (|s\rangle), so it is a reflection across the line along (|s\rangle).
The composition of two reflections is a rotation. In this two–dimensional picture, (G = D O_f) rotates vectors in the (|w\rangle)–(|r\rangle) plane by an angle (2\theta) toward (|w\rangle):
[
G|w\rangle = \cos(2\theta),|w\rangle + \sin(2\theta),|r\rangle,\qquad G|r\rangle = -\sin(2\theta),|w\rangle + \cos(2\theta),|r\rangle,
]
and in particular,
[
G^k |s\rangle = \sin\big((2k+1)\theta\big),|w\rangle + \cos\big((2k+1)\theta\big),|r\rangle.
]
Geometrically, you can imagine starting from (|s\rangle), which is at a small angle (\theta) away from the “unmarked” direction (|r\rangle). Each application of (G) rotates the state vector by (2\theta) toward the marked direction (|w\rangle). The probability of measuring the marked state after (k) iterations is (\sin^2((2k+1)\theta)).
To maximize that probability, you want ((2k+1)\theta) as close as possible to (\tfrac{\pi}{2}), i.e. rotate the initial vector onto the (|w\rangle) axis. Solving ((2k+1)\theta \approx \pi/2) with (\theta = \arcsin(1/\sqrt{N})) gives
[
k \approx \frac{\pi}{4},\sqrt{N}
]
for large (N) (more precisely, (k = \left\lfloor \tfrac{\pi}{4}\sqrt{N},\right\rfloor) for one marked item). This square–root scaling reflects the fact that each iteration increases the marked amplitude by an additive amount on the order of (1/\sqrt{N}), so you need (O(\sqrt{N})) steps to build it up to order 1.