Skip to content

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 f:{0,1}n{0,1}f:\{0,1\}^n\to\{0,1\} — feed it an nn-bit string, it spits out one bit. They promise ff 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

2n2+1=2n1+1 queries(9.7.1)\frac{2^n}{2}+1=2^{n-1}+1\ \text{queries}\tag{9.7.1}

— if half the inputs have come back identical, only query number 2n1+12^{n-1}+1 can settle it. For n=100n=100 that is about 6.3×10296.3\times10^{29} 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:

Ufxy=xyf(x)(9.7.2)U_f\ket{x}\ket{y}=\ket{x}\ket{y\oplus f(x)}\tag{9.7.2}

(\oplus is addition mod 2; applying it twice undoes it, so it really is unitary.) The first move anyone thinks of: use a row of HH‘s to build the superposition of all inputs, then query once:

Uf(12nxx)0=12nxxf(x)(9.7.3)U_f\left(\frac{1}{\sqrt{2^n}}\sum_x\ket{x}\right)\ket{0} =\frac{1}{\sqrt{2^n}}\sum_x\ket{x}\ket{f(x)}\tag{9.7.3}

One call, and all 2n2^n function values have been computed — that is quantum parallelism. But hold the celebration: measure this state and it collapses randomly onto a single (x,f(x))(x, f(x)) 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 f(x)f(x)‘s must be funnelled into the probability distribution of the measurement outcome. The wrench that does the funnelling is called phase kickback.

Hand-compute the smallest case first: the Deutsch algorithm (n = 1)

For n=1n=1 there are four possible ff‘s: constant (f0f\equiv0, f1f\equiv1), balanced (f(x)=xf(x)=x, f(x)=1xf(x)=1-x). The decision problem boils down to one bit: f(0)f(1)=?f(0)\oplus f(1)=? (0 ⇒ constant, 1 ⇒ balanced). The circuit:

|0⟩ ──[H]──┬──────[H]──[measure] → 0: constant / 1: balanced
           │Uf
|−⟩ ───────┴────────────────── (ancilla stays |−⟩ throughout)

Step by step (the ancilla stays \ket{-}; we write only the first qubit):

0 H 0+12 Uf (1)f(0)0+(1)f(1)12(9.7.6)\ket{0} \ \xrightarrow{H}\ \frac{\ket{0}+\ket{1}}{\sqrt2} \ \xrightarrow{U_f}\ \frac{(-1)^{f(0)}\ket{0}+(-1)^{f(1)}\ket{1}}{\sqrt2}\tag{9.7.6}

Pull out the global phase (1)f(0)(-1)^{f(0)} (unobservable — discard):

=0+(1)f(0)f(1)12={+,constant,balanced=\frac{\ket{0}+(-1)^{f(0)\oplus f(1)}\ket{1}}{\sqrt2} =\begin{cases}\ket{+},&\text{constant}\\[2pt]\ket{-},&\text{balanced}\end{cases}

The final HH rotates ±\ket{\pm} back to the computational basis:

+H0 (constant),H1 (balanced)(9.7.7)\ket{+}\xrightarrow{H}\ket{0}\ (\text{constant}),\qquad \ket{-}\xrightarrow{H}\ket{1}\ (\text{balanced})\tag{9.7.7}

Measure the first qubit and read the answer deterministically. One query has extracted f(0)f(1)f(0)\oplus f(1), which classically takes two — note that we did not obtain the individual values of f(0)f(0) and f(1)f(1), 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)

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 NN drawers hides a key, opening a drawer costs one look, and classically you open N/2N/2 on average. Can quantum open fewer? Next section, Grover’s algorithm answers N\sqrt N — 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