Grover search on two qubits
Find the marked item among four with a single Grover iteration, which is exact for N = 4.
Intermediate · 2 qubits · 12 gates · 2 two-qubit · depth 7 · reviewed November 2026
Open in the Circuit BuilderWhat is happening
Grover’s algorithm amplifies the amplitude of a marked state. Here the oracle marks |11⟩ by flipping its sign using a CZ gate. The diffusion step, H, X, CZ, X, H, reflects every amplitude about the average, which raises the marked one.
For four items one iteration is exact, and the marked state has probability 100%. For larger N the best success needs about the square root of N iterations.
Step by step
1. Uniform superposition
H on both qubits gives every basis state amplitude ½.
2. Oracle
CZ flips the sign of |11⟩ only.
3. Diffusion
H, X, CZ, X, H reflect the amplitudes about their mean, which turns the sign difference into a probability difference.
Expected result
|11⟩ with 100% probability.
Qubit 0 is the leftmost bit. In Qiskit, bitstrings are printed in the reverse order.
Qiskit code
from qiskit import QuantumCircuit from math import pi qc = QuantumCircuit(2, 2) qc.h(0) qc.h(1) qc.barrier() qc.cz(0, 1) qc.barrier() qc.h(0) qc.h(1) qc.barrier() qc.x(0) qc.x(1) qc.barrier() qc.cz(0, 1) qc.barrier() qc.x(0) qc.x(1) qc.barrier() qc.h(0) qc.h(1) qc.barrier() qc.measure(0, 0) qc.measure(1, 1) # Qiskit prints bit strings with qubit 0 on the RIGHT; this site writes qubit 0 on the LEFT.
Try this
- Mark |01⟩ by wrapping the oracle CZ with X gates on q0.
- Run two iterations and see the success probability fall again.
- Compare with the Grover builder.
Gates used
Related reading
Questions
Why does a second iteration make it worse?
Grover’s algorithm rotates the state toward the target by a fixed angle each time. Past the optimal count it rotates beyond the target.