Part V · Chapter 25

Deutsch's Algorithm

Read ~16 min Prerequisites Ch. 22–23 Tools live one-query widget, code cell Live
Basic

This is the smallest possible quantum algorithm — one qubit, one oracle query — and it's the first one in history. Every piece of machinery from Ch. 22–23 (superposition, parallelism, phase oracles) gets used here for the very first time, on the simplest problem that can show a genuine quantum advantage at all.

The problem

You're given a black-box function f: {0,1}→{0,1}. There are exactly 4 possible such functions — 2 are constant (f(0)=f(1)) and 2 are balanced (f(0)≠f(1)). Question: which kind is it? Classically, this needs 2 queries in the worst case (check f(0), then f(1) to compare). Deutsch's algorithm needs exactly 1.

Fig. 25.1 — the full circuit1 qubit, 1 oracle call
|0⟩ H Uf H M
H, oracle, H, measure. This exact pattern — H-layer, oracle, H-layer, measure — is the skeleton of every algorithm through Ch. 27.
Intermediate

Working the math by hand

Start at |0⟩, apply H: (|0⟩+|1⟩)/√2. Apply the phase oracle: (−1)^f(0)|0⟩+(−1)^f(1)|1⟩, all over √2. Apply H again — this is exactly the Hadamard transform from Ch. 22, run backward. If f is constant, both terms share the same sign, and H constructively reconstructs |0⟩ exactly. If f is balanced, the terms have opposite signs, and H instead reconstructs |1⟩ exactly. Either way, the final measurement is 100% certain — no probability, no repeated trials needed.

Fig. 25.2 — pick any of the 4 functions, run itreal circuit, real certainty

All 4 possible 1-bit functions give a 100%-certain answer — try each one and confirm none of them ever land at 50/50.
Advanced

Why this counts as "faster," carefully

The honest statement of Deutsch's advantage is subtler than "twice as fast," and worth getting right: for this 1-bit problem, 1 query versus a classical worst-case of 2 is a real but modest speedup — the actual significance is historical and structural, not the size of the number. This was the first proof that quantum query complexity can be strictly less than classical query complexity for any problem at all, and the H–oracle–H pattern it introduced is exactly the template Ch. 26's Deutsch–Jozsa algorithm scales up to an exponential gap (1 query versus up to 2ⁿ⁻¹+1 classically) by simply running the same circuit on n qubits instead of one.

Fig. 25.3 — code, runs in your browser
All 4 rows print a definite outcome (0 or 1) every time, never a probability — matching Fig. 25.2 exactly.
Check your understanding

How many oracle queries does Deutsch's algorithm need, and how many does the best classical approach need in the worst case?

1 quantum query versus 2 classical queries in the worst case.

Check your understanding

What does measuring "0" at the end of the circuit tell you about f?

f is constant — the two phase terms shared the same sign, so the second H constructively reconstructed |0⟩.

Check your understanding

Is the final measurement probabilistic or certain?

Certain — 100% probability for the correct answer, every single time, for all 4 possible functions. No repeated trials are needed.

Check your understanding

What's the circuit "skeleton" Deutsch's algorithm introduces that later chapters reuse?

H-layer, oracle query, H-layer, measure. Ch. 26's Deutsch–Jozsa algorithm is exactly this same pattern, just scaled up to n qubits.

Check your understanding

Why is Deutsch's algorithm historically significant, beyond the modest 1-vs-2 query improvement?

It was the first proof that quantum query complexity can be strictly lower than classical query complexity for any problem at all — the conceptual breakthrough mattered more than the specific (small) size of the speedup.

Review queue

Scroll back to a chapter's quiz cards to review them once they're due — a full cross-chapter queue view is a planned upgrade.