9.7
The Deutsch-Jozsa algorithm
The first clean example of quantum speedup: phase kickback writes the function values into phases, and interference reads out "constant or balanced" in one go — classically 2ⁿ⁻¹ + 1 queries in the worst case, quantumly just 1.
Recommended first
After this section you should be able to
- State the Deutsch–Jozsa problem and show the classical worst case needs 2ⁿ⁻¹ + 1 queries
- Hand-compute the full state evolution of the single-qubit Deutsch algorithm and point to the step where interference happens
- Explain phase kickback: why the function value ends up in the phase
- Make clear why "quantum parallelism" alone is not enough — the speedup only cashes out with interference
The entanglement protocols of the past few sections solved communication problems. This section switches battlefields: computation. We will watch quantum mechanics beat the classical world at computing for the first time, cleanly — and the way it wins is not “calculating faster” but “asking fewer questions”.
The problem at the door: can one question identify both faces of a coin?
Someone hands you a black box (an oracle) containing a function — feed it an -bit string, it spits out one bit. They promise is one of exactly two kinds:
- Constant: every input gives the same output (all 0 or all 1);
- Balanced: exactly half the inputs give 0, the other half give 1.
The task: decide which. The only thing you can do is query — feed one input, see one output. Question: how few queries suffice?
The classical bill. With luck, 2 queries (two different outputs ⇒ balanced). But to declare “constant” beyond all doubt, the worst case requires
— if half the inputs have come back identical, only query number can settle it. For that is about queries; the age of the universe would not cover it. The quantum algorithm queries once.
Why naive “quantum parallelism” is not enough
The quantum black box must be reversible (section 9.2); the standard construction adds an ancilla wire:
( is addition mod 2; applying it twice undoes it, so it really is unitary.) The first move anyone thinks of: use a row of ‘s to build the superposition of all inputs, then query once:
One call, and all function values have been computed — that is quantum parallelism. But hold the celebration: measure this state and it collapses randomly onto a single pair, no different from one classical query. Section 9.1’s old lesson: information stored in a state ≠ information you can take out. Quantum parallelism is the necessary fuel; interference is the spark — the information of all the ‘s must be funnelled into the probability distribution of the measurement outcome. The wrench that does the funnelling is called phase kickback.
Phase kickback: moving the function value into the phasebasic~5 min
Prepare the ancilla in and feed it to :
Two cases:
- : the ancilla is , untouched;
- : the ancilla is , an extra minus sign.
Both cases in one line:
The ancilla stays throughout, and the function value has become a phase on the branch. For a single , a global phase means nothing; but in a superposition, each branch collects its own sign — they become relative phases, and relative phases are the control lever of interference (section 9.2’s lesson from ).
Hand-compute the smallest case first: the Deutsch algorithm (n = 1)
For there are four possible ‘s: constant (, ), balanced (, ). The decision problem boils down to one bit: (0 ⇒ constant, 1 ⇒ balanced). The circuit:
|0⟩ ──[H]──┬──────[H]──[measure] → 0: constant / 1: balanced
│Uf
|−⟩ ───────┴────────────────── (ancilla stays |−⟩ throughout)
Step by step (the ancilla stays ; we write only the first qubit):
Pull out the global phase (unobservable — discard):
The final rotates back to the computational basis:
Measure the first qubit and read the answer deterministically. One query has extracted , which classically takes two — note that we did not obtain the individual values of and , only one global property of theirs. Quantum speedup always plays this game: surrender pointwise information, gain global information.
The general case: n-qubit Deutsch–Jozsa
|0⟩ ──[H]──┬─────[H]──[measure]┐
|0⟩ ──[H]──┤Uf [H]──[measure]├─ all 0: constant / otherwise: balanced
⋮ ⋮ │ ⋮ ⋮ │
|−⟩ ───────┴───────────────────┘ (ancilla not measured)
How interference concentrates the answer onto the all-zero stringadvanced~8 min
Step 1: prepare and query. copies of go through a row of ‘s, then phase kickback:
Step 2: another row of ‘s. We need the formula for acting on basis states. For one qubit, (check by substituting ); for bits, multiply bit by bit:
Substituting gives the final state:
Step 3: look only at the amplitude of the all-zero string . There :
- Constant: all terms share one sign, . Probability — every branch interferes constructively and floods into the all-zero string; the measurement is certain to give .
- Balanced: half ‘s, half ‘s, cancelling in pairs, — the all-zero string is emptied by destructive interference; the measurement is certain to give a non-zero string.
The verdict: an all-zero readout ⇒ constant; any non-zero bit ⇒ balanced. One query, zero error rate.
The picture
The speedup in three acts. Looking back over the whole run, the quantum advantage is a relay of three things: (1) superposition lets one query touch every input; (2) phase kickback transcribes each function value into a branch phase; (3) interference (the final row of ‘s) lets the phases decide the measurement distribution by “collective vote” — a constant function passes unanimously into the all-zero string, a balanced function’s votes cancel half against half. Remove any link and you fall back to classical: without interference it is a lottery, without phase kickback the branches are indistinguishable, without superposition there are no votes to cast.
The mathematics
Query-complexity comparison (for an error-free decision):
Exponential versus constant. But honesty requires a footnote: if the classical algorithm may sample randomly times and tolerate error probability , it too needs only a constant number of queries. So DJ’s exponential advantage strictly holds in the “exact decision” sense — it is a demonstration of principle, not a practical algorithm.
Key formulas
Quantum oracle
The function query made reversible; applying twice undoes it
Phase kickback
Set the ancilla to ∣−⟩ and the function value moves into the phase
Hadamard transform
x·y is the mod-2 sum of bitwise products
Decision amplitude
Constant ⇒ all-zero string guaranteed; balanced ⇒ non-zero string guaranteed
Self-check4 questions
- 1.
n = 3 (8 inputs). To decide constant/balanced beyond all doubt, how many queries does a classical algorithm need in the worst case?
0% relative tolerance - 2.
What state must the ancilla be in for phase kickback?
- 3.
The algorithm ends and you measure the all-zero string 00…0. What does that tell you?
- 4.
Which statements about "quantum parallelism" are correct? (Select all that apply.)
Select all that apply
What comes next
Deutsch–Jozsa is an exhibition match tailor-made for quantum mechanics: the problem is artificial, and classical randomised algorithms handle it easily too. A real-world problem looks like this: one of drawers hides a key, opening a drawer costs one look, and classically you open on average. Can quantum open fewer? Next section, Grover’s algorithm answers — and we will see it with perfect clarity in a purely geometric picture: two mirrors squeezing out a rotation.
Section 71 of 106 · use ← → to turn the page