The four Boolean functions, the reversible oracle, and the single-query Deutsch circuit with full derivation.
Deutsch’s Algorithm determines whether a single-bit function f(x) is constant (f(0) = f(1)) or balanced (f(0) ≠ f(1)) using only one oracle query. To understand how the algorithm works, we first need to see how each possible function is physically realised as a reversible quantum gate, and then how the complete Deutsch circuit encodes that function into a measurable phase difference.
1 · The 4 Possible Functions
With a single input bit x ∈ {0,1} and output bit f(x) ∈ {0,1}, there are exactly four possible Boolean functions. Two are constant (output ignores the input) and two are balanced (output depends on the input).
| # | Name | f(0) | f(1) | Gate implementation | Type |
|---|---|---|---|---|---|
| 1 | Constant Zero | 0 | 0 | Identity — no gates needed | Constant |
| 2 | Constant One | 1 | 1 | X gate on output wire only | Constant |
| 3 | Balanced ID | 0 | 1 | CNOT (x = control, y = target) | Balanced |
| 4 | Balanced NOT | 1 | 0 | X on x, CNOT, X on x (flip, copy, restore) | Balanced |
The two balanced oracles as quantum circuits. Both have x on the control wire and y on the target wire, with the bottom wire carrying y ⊕ f(x) as output.
Balanced ID — f(x) = x
Balanced NOT — f(x) = ¬x
2 · The General Oracle Uf
All four functions are wrapped in a single reversible gate Uf that leaves the input register unchanged and XORs the function value into the output register:
As a two-wire circuit, Uf passes x unchanged on the top wire while the bottom wire carries y ⊕ f(x). The box spans both wires to show they are processed jointly by a single gate:
The reversibility of Uf is guaranteed because XOR is its own inverse: applying Uf twice returns the original state. This property allows quantum algorithms to query f without destroying the superposition.
3 · The Complete Deutsch Circuit
The algorithm wraps Uf in Hadamard gates on both wires. Initialise q[0] = |0⟩ and q[1] = |1⟩, apply H to both, query Uf once, apply a final H to q[0], then measure q[0]:
The three states at each checkpoint:
| State | Expression | Note |
|---|---|---|
| |ψ₀⟩ | |0⟩|1⟩ | Initialisation |
| |ψ₁⟩ | |+⟩|−⟩ = ½(|0⟩+|1⟩)(|0⟩−|1⟩) | After both H gates |
| |ψ₂⟩ | (1/√2)[(−1)^f(0)|0⟩+(−1)^f(1)|1⟩] ⊗ |−⟩ | After Uf, before final H |
4 · Mathematical Proof
The full derivation follows four steps. Each is exact; no approximation is involved.
|ψ₀⟩ = |0⟩|1⟩
Step 2 — Apply H to both wires:
|ψ₁⟩ = |+⟩|−⟩
= (1/√2)(|0⟩ + |1⟩) ⊗ (1/√2)(|0⟩ − |1⟩)
Step 3 — Apply U_f (phase kickback on |−⟩ target):
U_f |x⟩|−⟩ = (−1)^f(x) |x⟩|−⟩
|ψ₂⟩ = (1/√2)[ (−1)^f(0)|0⟩ + (−1)^f(1)|1⟩ ] ⊗ |−⟩
Step 4 — Apply H to q[0] and inspect cases:
Constant f(0) = f(1) = c:
|ψ₂⟩ = (−1)^c (1/√2)(|0⟩ + |1⟩) ⊗ |−⟩
After H: (−1)^c |0⟩ ⊗ |−⟩ → Measure 0
Balanced f(0) ≠ f(1):
|ψ₂⟩ = ±(1/√2)(|0⟩ − |1⟩) ⊗ |−⟩
After H: ±|1⟩ ⊗ |−⟩ → Measure 1
5 · Final Measurement
The measurement of q[0] after the final Hadamard gives a deterministic result in both cases:
| Measure q[0] | Function type | Why |
|---|---|---|
| 0 | Constant | f(0) ⊕ f(1) = 0; amplitudes add constructively on |0⟩ |
| 1 | Balanced | f(0) ⊕ f(1) = 1; amplitudes cancel on |0⟩, survive on |1⟩ |
A classical algorithm must evaluate f(0) and f(1) separately, requiring two queries. Deutsch’s algorithm queries Uf exactly once, using superposition to probe both inputs simultaneously and interference to extract a global property of the function. This is the first demonstrated quantum computational advantage over any classical approach.
Malcolm Low is an Associate Professor at the Singapore Institute of Technology, writing on quantum computing, programming, and applied computing from Singapore.
Website: malcolmlow.com · Singapore
Quantum Series 2026 · Built with Qiskit 1.x
✦ This article was generated with the assistance of Claude by Anthropic ✦
Share this:
- Share on X (Opens in new window) X
- Share on Facebook (Opens in new window) Facebook
- Print (Opens in new window) Print
- Email a link to a friend (Opens in new window) Email
- Share on LinkedIn (Opens in new window) LinkedIn
- Share on Reddit (Opens in new window) Reddit
- Share on Tumblr (Opens in new window) Tumblr
- Share on Threads (Opens in new window) Threads
- Share on Pinterest (Opens in new window) Pinterest
- Share on Telegram (Opens in new window) Telegram
- Share on WhatsApp (Opens in new window) WhatsApp
- Share on Bluesky (Opens in new window) Bluesky
3 thoughts on “Deutsch’s Algorithm in Quantum Computing: The 4 Cases”