Grover’s Search Algorithm
Derive Grover's two-reflection search mechanism, its stopping rule and its quadratic query advantage.
- Calculate one eight-item Grover iteration completely.
- Use the good-subspace rotation formula to explain overshooting.
- State the oracle and marked-fraction assumptions behind the query bound.
Search by rotating probability toward a target
Section titled “Search by rotating probability toward a target”Grover’s algorithm searches a set of N labels using a predicate that recognises good labels. It alternates two reflections. One changes the sign of good amplitudes; the other reflects about the prepared uniform state. Together they rotate the state toward the good subspace. A measurement at a planned stopping point yields a candidate, which should then be checked.
Review the four-item interference example and oracle access. The basic arithmetic uses signed real amplitudes. The geometric description explains why more iterations eventually reduce success rather than improving it indefinitely.
The search contract
Section titled “The search contract”The predicate marks M of N basis labels, with zero less than M less than N in the basic analysis. Coherent access is provided by a phase oracle that negates marked components. The output is one marked label, not a list of every solution. Verification evaluates the predicate on the measured candidate.
For one unknown marked item, the quantum query count grows as the square root of N for bounded success probability. Classical unstructured search has linear query growth. This is a quadratic black-box advantage. If an application has exploitable structure, compare with the best classical use of that structure rather than assuming exhaustive search is automatically the right baseline.
Procedure
Section titled “Procedure”Prepare the uniform state over all labels. Apply the phase oracle. Apply diffusion, the reflection about the uniform state. Repeat that pair a chosen number of times, then measure and verify. Diffusion on a vector with mean amplitude m maps each entry a to twice m minus a.
When N is a power of two, H on every input qubit prepares the uniform state. The diffusion reflection can be constructed by combining that preparation, a phase reflection about zero and its inverse. Its global sign convention can vary without changing the isolated search probabilities. Keep conventions consistent when embedding the iterate in controlled estimation circuits.
For a worked diagram, use three amplitude panels: all entries positive, one entry negative, then a larger marked entry after diffusion. A separate circular arrow can indicate the two-dimensional rotation and the need to stop near its peak.
Worked example: eight labels, one marked
Section titled “Worked example: eight labels, one marked”Initially every amplitude is a equal to one over the square root of eight. After the oracle, seven entries are a and one is negative a. The mean is six a divided by eight, or three a over four. Diffusion maps an unmarked entry to a over two and the marked entry to five a over two.
The marked probability is therefore 25 divided by 32, or 78.125 percent. Each unmarked probability is one divided by 32, and the total probability remains one. This verifies the whole distribution rather than only noticing that the target bar increased.
After two iterations, the marked probability is 121 divided by 128, about 94.53 percent. After three it falls substantially. No observation was made between iterations; the state evolves coherently. A procedure that measures after each oracle and then continues on the collapsed basis state is not Grover’s algorithm.
Why two reflections produce amplification
Section titled “Why two reflections produce amplification”Let the good direction be the uniform superposition over marked labels, and the bad direction the uniform superposition over unmarked labels. The initial state lies in the plane spanned by those directions. Its good amplitude is the square root of M over N. Define theta by sine theta equal to that quantity.
The phase oracle reflects one direction, and diffusion reflects about the initial vector. Their composition rotates the state by twice theta. After k iterations the good probability is
This formula is a correctness statement for the ideal symmetric setting. Choose an integer k near the first peak. For a small marked fraction, the scale is approximately pi over four times the square root of N over M. Exact stopping depends on the fraction and integer rounding. Unknown M requires a suitable search or estimation strategy rather than a guessed fixed schedule.
Special and boundary cases
Section titled “Special and boundary cases”Four labels with one marked have theta equal to pi over six, so one iteration reaches the peak exactly. That convenient teaching example is exceptional. Eight labels do not reach certainty at the same iteration count. If no labels are marked, verification never succeeds and the basic nonzero-M analysis does not provide a stopping certificate. If every label is marked, ordinary measurement already succeeds.
Multiple marked items are amplified together. The final measurement returns one of them according to the resulting state, rather than printing all M items. If the application needs many distinct solutions, it must account for additional runs, duplicate handling and the output size. Search and enumeration are different tasks.
Practical costs and limitations
Section titled “Practical costs and limitations”One oracle call may contain a large reversible computation, workspace and uncomputation. Diffusion also has synthesis costs, especially in large registers. Hardware analysis must include native gate counts, connectivity, precision and error correction. A browser simulation stores amplitudes classically and cannot demonstrate a quantum hardware runtime advantage by its own timing.
For an experiment, predict the full eight-entry vector after one iteration, then compare the simulator table. Change only the iteration count and make another prediction. Separately vary shots to observe sampling uncertainty around the fixed ideal probabilities. Keep iteration effects and finite-shot fluctuations conceptually distinct.
Exercises
Section titled “Exercises”-
For four labels and one marked item, calculate the mean amplitude after marking and each amplitude after diffusion.
-
A designer doubles the number of Grover iterations whenever the marked histogram bar rises. Explain why that is not a reliable stopping rule, even before hardware noise is considered.
Worked answers
-
The amplitudes are three positive halves and one negative half, so the mean is one quarter. Unmarked entries become zero; the marked entry becomes one. The final measurement succeeds with certainty in this ideal four-item case.
-
Success oscillates with iteration count. More iterations can pass the first peak and reduce the probability. Observing histograms also requires separate circuit runs and finite shots. A stopping strategy must use the known or estimated marked fraction and a planned success analysis, not an assumption of monotonic improvement.
Source
Section titled “Source”Grover’s original paper introduces the search advantage. The exact rotation and generalised preparation framework are developed further in amplitude amplification and estimation.
Predict and test
Section titled “Predict and test”Choose three input qubits and one Grover iteration to test the eight-item calculation. Predict the marked probability and every unmarked probability before revealing. Compare later iterations to see why amplification needs a stopping rule.
Grover search explorer
A phase oracle marks one item; diffusion reflects amplitudes about their mean. Amplification can overshoot. Oracle construction and hardware costs are excluded.
Prepare your experiment using the controls. Record a prediction, then reveal the statevector or run the experiment.
Changing the preparation or circuit starts a new prediction.
Take it further
For four items, trace all amplitudes through one iteration. For eight, compare iterations 0–6 and explain the oscillation.
Initial setup · reference state
Marked item probability 100.0%
| Basis | Amplitude a + bi | Magnitude | Phase (rad) | Probability |
|---|---|---|---|---|
| |00⟩ | 0 + 0i | 0.000000 | undefined | 0.0% |
| |01⟩ | 0 + 0i | 0.000000 | undefined | 0.0% |
| |10⟩ | 0 + 0i | 0.000000 | undefined | 0.0% |
| |11⟩ | 1 + 0i | 1.000000 | 0.000000 | 100.0% |
Signs and complex phases are part of the state. Phase is undefined for a zero amplitude. A shared global phase changes no probabilities; relative phases can affect a later operation. Values are rounded to six decimal places.
Prediction to try: Predict the marked item’s success probability at this register size and iteration count. Explain an expected increase or decrease.
Challenge: For four items, trace all amplitudes through one iteration. For eight, compare iterations 0–6 and explain the oscillation.
Open the live experiment studioTrace the circuit or amplitudes
Section titled “Trace the circuit or amplitudes”Check your understanding
Section titled “Check your understanding”What is the marked probability after one ideal Grover iteration among eight labels?
Answer: 25/32. The marked amplitude becomes (5/2)/√8, whose squared magnitude is 25/32. The exact-one-iteration result applies to the special four-item case.
Ready for the next step?
Your progress stays in this browser.