|q⟩ Bad Qubits

intermediate · Programming · Grover's Search Algorithm

Amplitude Geometry

Before you can understand why Grover's algorithm works, you need to see the state vector through a geometric lens. In this lesson we reduce the full 2n2^n-dimensional Hilbert space to a two-dimensional picture that makes every step of the algorithm visually obvious.

The two-subspace decomposition

Label the single marked basis state ω|\omega\rangle and collect every other computational basis state into the equal superposition

ω=1N1xωx,|\omega^\perp\rangle = \frac{1}{\sqrt{N-1}} \sum_{x \neq \omega} |x\rangle,

where N=2nN = 2^n. The set {ω,ω}\{|\omega\rangle,\, |\omega^\perp\rangle\} is an orthonormal basis for the two-dimensional plane that Grover's algorithm never leaves. Every state the algorithm visits is a linear combination of these two vectors.

The initial state as an angle

The uniform superposition produced by Hn0H^{\otimes n}|0\rangle is

s=1Nx=0N1x.|s\rangle = \frac{1}{\sqrt{N}}\sum_{x=0}^{N-1}|x\rangle.

Decomposed into the two-subspace basis this is

s=sinθω+cosθω,|s\rangle = \sin\theta\,|\omega\rangle + \cos\theta\,|\omega^\perp\rangle,

where the angle θ\theta satisfies

sinθ=ωs=1N.\sin\theta = \langle\omega|s\rangle = \frac{1}{\sqrt{N}}.

For N=4N = 4 (two qubits) this gives θ=arcsin(1/2)=30°\theta = \arcsin(1/2) = 30°, while for N=1024N = 1024 it gives θ1.8°\theta \approx 1.8° — the initial state is nearly perpendicular to the target.

Visualizing the plane

Draw a unit circle in the ω|\omega^\perp\rangleω|\omega\rangle plane (horizontal and vertical axes respectively). The initial state s|s\rangle sits at angle θ\theta from the horizontal axis. The goal is to rotate the state vector to 90°90°, i.e., to ω|\omega\rangle itself.

Goal: rotate sGrover iterationsω.\text{Goal: rotate } |s\rangle \xrightarrow{\text{Grover iterations}} |\omega\rangle.

Each Grover iteration is a rotation by 2θ2\theta in this plane:

  1. Oracle reflection: reflect about the ω|\omega^\perp\rangle axis (the horizontal). This moves the angle from α\alpha to α-\alpha, negating the component along ω|\omega\rangle.
  2. Diffuser reflection: reflect about s|s\rangle. Combined with step 1, the net effect is a rotation by +2θ+2\theta toward ω|\omega\rangle.

After kk iterations the state is at angle (2k+1)θ(2k+1)\theta, so the amplitude on the marked state is

sin((2k+1)θ).\sin((2k+1)\theta).

This equals 1 — perfect retrieval — when (2k+1)θ=π/2(2k+1)\theta = \pi/2, giving

k=π/2θ2θ=π4θ12.k = \frac{\pi/2 - \theta}{2\theta} = \frac{\pi}{4\theta} - \frac{1}{2}.

Using θ1/N\theta \approx 1/\sqrt{N} for large NN, the optimal number of iterations is kπ4Nk \approx \tfrac{\pi}{4}\sqrt{N}, recovering the famous O(N)O(\sqrt{N}) speedup.

The two-qubit case: exact geometry

For n=2n = 2, N=4N = 4, θ=30°\theta = 30°. One iteration rotates by 2×30°=60°2 \times 30° = 60°, bringing the state from 30°30° to 90°90°: exactly ω|\omega\rangle. The probability of success after one step is sin2(90°)=1\sin^2(90°) = 1. This is why the two-qubit Grover algorithm finds the marked item with certainty in a single iteration — not just very likely, but with probability exactly 1.

Amplitudes are coordinates

In the two-dimensional picture, the state at any point in the algorithm is a unit vector

ψ=αω+βω,α2+β2=1.|\psi\rangle = \alpha|\omega\rangle + \beta|\omega^\perp\rangle, \qquad |\alpha|^2 + |\beta|^2 = 1.

The probability of finding the marked item on measurement is α2=sin2((2k+1)θ)|\alpha|^2 = \sin^2((2k+1)\theta). By maximizing α\alpha and minimizing β\beta over the course of O(N)O(\sqrt{N}) reflections, Grover transfers probability mass from the entire non-target subspace into the single target state — this process is called amplitude amplification, and the geometric picture makes it transparent.

Sign in on the full site to ask questions and join the discussion.