Capstone: Design an Algorithm Demo
You have now studied the Quantum Fourier Transform, Grover's search, phase estimation, and benchmarking. A capstone project does not simply run one of these algorithms in isolation — it asks you to select the right tool and wire it together correctly for a concrete goal.
In this capstone you design a complete Grover search demo for a marked state of your choosing. Along the way you will see that the two principal ingredients — the oracle and the diffuser — compose cleanly regardless of which state is marked, as long as the oracle is constructed correctly.
What makes a good algorithm demo
A convincing algorithm demo has three properties:
- Correctness — the output distribution concentrates on the answer with the theoretically predicted probability.
- Transparency — every gate has a reason; a reader can trace why each step is necessary.
- Generalisability — the structure extends to larger instances, even if the demo itself is small.
Grover's algorithm on two qubits satisfies all three. For computational basis states with one marked state, the theoretical success probability after one iteration is
Exactly 100 % of the probability lands on the marked state.
Changing which state is marked
Every Grover circuit starts with the same diffuser. What changes is the oracle — the phase-kickback unitary that multiplies the marked state by and leaves all other states unchanged.
The general recipe for building an oracle that marks with a two-qubit CZ:
- CZ applies only when both control and target are in state .
- For each qubit where , conjugate with so that qubit is flipped to exactly when the input bit is .
For (qubit 0 is 1, qubit 1 is 0):
The gates on qubit 1 ensure the CZ fires when qubit 0 is and qubit 1 is , which is precisely the state.
The Grover diffuser, revisited
The diffuser implements a reflection about the uniform superposition . Written as a unitary,
where . Because maps to , conjugating by converts the reflection about into a reflection about :
The inner operator is a controlled phase flip on the all-zeros state, which is built from , a multi-controlled-, and again — the same pattern as the oracle, but always targeting .
Putting it together
A complete one-iteration Grover demo for marking on two qubits:
| Layer | Gates | Purpose | |-------|-------|---------| | Superposition | | Start from | | Oracle | | Phase-flip | | Diffuser | | Reflect about |
Total: 14 gates. The result: all probability on .
Try it
Complete the circuit by filling in all three layers. The grader checks the output distribution — it must place all probability on the outcome.
Once you pass the grader, reflect on the structure: the diffuser was identical to the one used in the demo earlier in this module — only the oracle changed. That is the power of composable algorithm primitives.
Sign in on the full site to ask questions and join the discussion.