Building the Two-Qubit QFT
The two-qubit QFT is the first case where controlled phase gates appear explicitly. Working through it by hand fixes the pattern used in all larger QFT circuits.
The QFT on two qubits
For qubits () the general formula
gives the four basis-state mappings:
Writing (with the most- and least-significant bits) and , the sum factors into a tensor product:
where the subscript labels the qubit. Each qubit ends in a superposition, but the phase of its component depends on the input bits. The phase on qubit 1 has two contributions: (from the more-significant bit) and (a finer half-turn from its own bit — together these encode the fractional binary expansion ).
The circuit
Three types of gate realize the factored product:
- Hadamard on qubit 0 — creates on the most-significant qubit.
- gate on qubit 1 — adds the phase to qubit 1's component, conditional on qubit 0 being . In circuit API notation this is with control qubit 0 and target qubit 1.
- Hadamard on qubit 1 — creates the superposition on the least-significant qubit.
- SWAP(0, 1) — reverses the output bit order to match the standard convention where the most-significant output sits in qubit 0.
The complete sequence is:
(gates applied right-to-left in time, i.e. acts first; standard matrix multiplication order).
Gate count and scaling
The two-qubit QFT uses 2 Hadamards, 1 controlled-phase gate, and 1 SWAP — 4 gates total. The general -qubit QFT uses Hadamards, controlled-phase gates, and SWAPs, for an circuit. This compares favourably with the classical fast Fourier transform which needs arithmetic operations on the same -point data.
Try it
The starter code has all four steps — only the controlled-phase rotation is missing. Add it between the two Hadamards. The grader checks the full unitary matrix, so an empty or incomplete circuit will fail.
Sign in on the full site to ask questions and join the discussion.