
Grover’s Search Algorithm: Find a Marked Item in Four Steps
Grover’s algorithm amplifies a marked answer in a four-item search. See how phase marking and diffusion work in a compact Qiskit circuit.
Imagine four sealed boxes, each holding a different number, and you can test a box only by asking a yes-or-no question: “Is this the one I want?” A classical search may need to check three boxes before the answer is certain. Grover’s algorithm offers a quantum alternative: it arranges the four possibilities so that one carefully chosen operation amplifies the marked answer, making it certain after a single search round in the ideal case.
This tiny example captures the central idea of Grover search. It is not magic parallel checking. It is a controlled way to make the right answer more likely when the search space has no useful structure to exploit.
1. Put the four possibilities into superposition
Two qubits can represent four candidates: 00, 01, 10, and 11. Start both qubits in zero, then apply a Hadamard gate to each. The result is an equal superposition: each candidate has the same amplitude, analogous to a probability weight that can be positive or negative.
That equal start is useful, but it has not identified anything. If we measured now, each candidate would appear with probability one quarter. Grover’s algorithm changes those amplitudes before measurement, using the problem’s answer test and a second operation called diffusion.
2. Ask an oracle to mark the answer
An oracle is a reversible circuit that recognizes a solution. In Grover search, it does not need to reveal the answer in a classical output bit. Instead, it flips the sign of the marked state’s amplitude, leaving the other states unchanged. This is called phase marking.
For a four-item example where 11 is the target, a controlled-Z gate applies a minus sign only when both qubits are one. The marked state now has a negative amplitude. A sign change alone does not affect its measurement probability, so the oracle by itself does not make the answer easier to see. The next step turns that phase difference into a larger amplitude.
3. Reflect amplitudes with diffusion
The diffusion operator reflects the amplitudes around their average. In practical terms, it boosts states whose amplitudes are below the average and reduces those above it. Since the oracle made the target amplitude negative, this reflection pushes that target upward while pushing the unmarked amplitudes downward.
For four candidates and one target, one oracle-plus-diffusion round transforms the equal superposition into the target state, in ideal arithmetic. Measuring then returns 11 with certainty. You can think of the oracle as creating contrast and diffusion as converting that contrast into a stronger chance of observing the answer.
4. Measure, and repeat only when needed
A Qiskit-friendly circuit for this specific case can be written with familiar gates. The first pair of Hadamards creates the superposition. cz is the oracle for target 11; the following Hadamard, X, controlled-Z, X, Hadamard sequence implements diffusion for two qubits.
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h([0, 1]) # Equal superposition of four states
qc.cz(0, 1) # Phase-mark |11>
qc.h([0, 1])
qc.x([0, 1])
qc.cz(0, 1)
qc.x([0, 1])
qc.h([0, 1]) # Diffusion
qc.measure_all()
Run the circuit on a simulator or quantum device and inspect the measured bit strings. On an ideal simulator, this example yields 11 every time. Real hardware can produce other results because gates and measurements are imperfect. Qiskit displays multi-qubit bit strings in classical register order, so when mapping results back to qubit labels, check the measurement wiring and bit ordering used by your circuit.
Why amplification helps, and where it stops
For a large unstructured search space of size N with one solution, Grover search needs on the order of √N oracle calls to find it with high probability, rather than up to N checks for a classical exhaustive search. With multiple solutions, the useful number of rounds depends on how many are marked. Too many rounds can rotate amplitudes past the target and make success less likely, so amplification is not something to repeat indefinitely.
The speedup counts calls to the oracle, not the cost of building it. If recognizing a valid answer is expensive, that reversible oracle may dominate the circuit. The algorithm also does not offer the same advantage when the data has structure that a classical method can exploit, and current quantum hardware adds noise and setup overhead. For four candidates, a classical check is already trivial. The example is valuable because it makes Grover’s mechanism visible: prepare possibilities, mark a phase, reflect about the average, then measure.