Checkpoint: Solve It in One Query
You have now seen every piece of the Deutsch–Jozsa algorithm: oracles, phase kickback, quantum parallelism, and interference. This checkpoint asks you to assemble those pieces into a complete working circuit and watch a quantum computer decide a property of a function in a single query — something no classical algorithm can match.
The problem
A function is hidden inside an oracle. You are promised that is either constant (same output for every input) or balanced (outputs 0 on exactly half of all inputs and 1 on the other half). Your goal is to decide which, using only one query to the oracle.
Classically, you would need up to queries in the worst case. The Deutsch–Jozsa algorithm does it in one.
The circuit structure
The circuit for uses three qubits: two input qubits () and one ancilla ().
Initialise. Prepare the ancilla in so that a Hadamard turns it into .
Fan out. Apply a Hadamard to every qubit. The input register becomes the uniform superposition over all four two-bit strings:
The ancilla is now , ready to kick back.
Query. Call the oracle exactly once. Because the ancilla is in , the oracle acts as a phase oracle on the input register:
The joint state of the input register after the query is
Interfere. Apply to the input register. The Hadamard transform maps this sum to a state concentrated on when is constant and spread away from when is balanced. Specifically, for the balanced function the final state of the input register is with certainty — a direct consequence of destructive interference cancelling all other outcomes.
Measure. Read qubits 0 and 1. Outcome 00 means constant; any other outcome means balanced.
Try it
Complete the circuit below. The oracle for the balanced function is already provided as a single CNOT gate — do not remove it. Your job is to add the correct initialisation steps before the oracle and the correct interference step after it, then measure.
After running, the probability histogram should show 100 and 101 each with probability 0.5
(qubit 0 = 1, qubit 1 = 0, ancilla in , reading from most-significant to least-significant).
The ancilla is never measured out of its state, so it contributes equal weight to both
outcomes. The input-register marginal is 10 with probability 1 — the non-00 outcome that
certifies the function is balanced, decided in a single query.
Sign in on the full site to ask questions and join the discussion.