|q⟩ Bad Qubits

intermediate · Programming · Grover's Search Algorithm

Over-Rotation

Grover's algorithm works by rotating the quantum state toward the marked item, a little further each iteration. If you stop at the right moment — after the optimal number of steps — the probability of finding the answer is nearly 1. But if you keep rotating, you overshoot: the amplitude of the marked state shrinks again, and eventually the probability distribution returns to something close to uniform. This is over-rotation.

The amplitude geometry

The state at any point lives in a 2D plane spanned by the marked basis state w|w\rangle and the uniform superposition of all unmarked states s|s'\rangle. Starting from the uniform superposition s|s\rangle, Grover's algorithm rotates toward w|w\rangle by a fixed angle 2θ2\theta per iteration, where

sinθ=1N.\sin\theta = \frac{1}{\sqrt{N}}.

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

Pk=sin2 ⁣((2k+1)θ).P_k = \sin^2\!\bigl((2k+1)\theta\bigr).

Over-rotation for N = 4

With only N=4N = 4 items (two qubits), sinθ=1/2\sin\theta = 1/2, so θ=π/6\theta = \pi/6. The optimal number of iterations is

k=π4θ=π4π/6=32=1.k^* = \left\lfloor \frac{\pi}{4\theta} \right\rfloor = \left\lfloor \frac{\pi}{4 \cdot \pi/6} \right\rfloor = \left\lfloor \frac{3}{2} \right\rfloor = 1.

One iteration is already perfect:

P1=sin2 ⁣(3π6)=sin2 ⁣(π2)=1.P_1 = \sin^2\!\left(3 \cdot \frac{\pi}{6}\right) = \sin^2\!\left(\frac{\pi}{2}\right) = 1.

Now apply a second iteration. The angle advances to 5θ=5π/65\theta = 5\pi/6:

P2=sin2 ⁣(5π6)=(12)2=14.P_2 = \sin^2\!\left(\frac{5\pi}{6}\right) = \left(\frac{1}{2}\right)^2 = \frac{1}{4}.

The success probability has collapsed from 100% back to 25% — exactly what you would get from a random guess! The state has rotated all the way past the target and landed near the opposite side of the plane.

The three unmarked states each end up with amplitude 1/2-1/2, probability 1/41/4 as well, so the output distribution is perfectly uniform across all four states. Running the circuit and measuring gives no useful information at all.

Why this matters in practice

For large NN, the optimal number of iterations is kπ4Nk^* \approx \tfrac{\pi}{4}\sqrt{N}. Every additional iteration beyond kk^* rotates the state away from the target. Because kk^* must be known in advance (it depends on NN and the number of solutions MM), running the algorithm blindly with too many iterations is as bad as running it with too few. Algorithms for the case where MM is unknown, such as quantum counting, address this by first estimating MM with quantum phase estimation.

Try it

Build the two-iteration Grover circuit for N=4N = 4, marking 11|11\rangle with a CZ oracle. After two full iterations the probability should be spread uniformly across all four basis states, confirming the over-rotation effect. The grader checks the output distribution.

Run your code to see the quantum state.

Inspect the histogram: each of the four outcomes should have probability close to 0.250.25. Compare this to the one-iteration result, where all probability sits on 11=3|11\rangle = |3\rangle.

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