Three-Qubit Grover
Scaling Grover's algorithm from 2 to 3 qubits takes us from to items and introduces the first non-trivial question: how many iterations do we need?
Optimal iteration count for eight items
The geometric analysis (see the Optimal Number of Iterations lesson) gives
where is the number of marked items. With , :
Two iterations push the success probability to
That is close to — but not quite — certainty; does not produce an exact multiple of the way did. A third iteration would over-rotate and lower the probability.
Oracle for a three-qubit marked state
Suppose we want to mark (qubit 0 is , qubit 1 is , qubit 2 is ). The standard approach converts a phase-flip oracle for into one for any target pattern by flipping the zero-valued qubits with before and after the core gate:
The gate itself is a three-qubit controlled- (CCZ). Because the circuit API provides CCX (Toffoli) rather than CCZ directly, we use the identity , extended to three qubits:
So the full oracle for is:
- — flip the zero qubit.
- , , — controlled-controlled-.
- — undo the flip.
The three-qubit diffuser
The diffuser reflects amplitudes about their mean. For qubits the pattern is always:
where the zero-phase-flip adds a only to . For three qubits the zero-phase-flip is again a CCZ gate (all controls on after the layer):
Putting it together
One full Grover iteration is: oracle then diffuser. With two iterations the procedure is:
- Apply to create the uniform superposition .
- Apply oracle + diffuser (iteration 1).
- Apply oracle + diffuser (iteration 2).
- Measure — outcome appears with probability .
Try it
The starter code provides the superposition and both diffuser blocks. Add the oracle for in each iteration. The grader checks the output distribution: (the 5th basis state in binary, index 5 counting from 0) must carry the dominant probability.
Sign in on the full site to ask questions and join the discussion.