|q⟩ Bad Qubits

intermediate · Programming · Grover's Search Algorithm

Two-Qubit Grover

Grover's algorithm searches an unstructured space of NN items in O(N)O(\sqrt{N}) steps. For N=4N = 4 (two qubits) a single iteration finds the marked item with certainty. Each iteration has two parts:

  1. Oracle — flip the sign (phase) of the marked basis state. To mark ∣11⟩|11\rangle we use a controlled-ZZ, since CZCZ multiplies exactly ∣11⟩|11\rangle by −1-1.
  2. Diffuser — reflect every amplitude about their mean ("inversion about the average"), amplifying the marked amplitude. The standard circuit is H⊗2 X⊗2 CZ X⊗2 H⊗2H^{\otimes 2}\,X^{\otimes 2}\,CZ\,X^{\otimes 2}\,H^{\otimes 2}.

Geometrically the two reflections rotate the state toward the marked item; for N=4N = 4 that single rotation lands exactly on ∣11⟩|11\rangle.

Try it

The starter code has the superposition and the diffuser — add the oracle that marks ∣11⟩|11\rangle. The grader checks the output distribution, which should put all probability on ∣11⟩|11\rangle.

Run your code to see the quantum state.

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