QuantumSimulator
Interactive Course
Interactive chapters from intuition to mastery
Structured Lessons
Eight modules with formulas and self-checks
Quantum Brain
Navigate lessons, laws, gates, devices, and tools
Guided Experiments
Hands-on circuits that teach one idea each
Circuit Lab
Build circuits, run them, and see the results
Gate Reference
Quick reference for all quantum gates
Cryostat Studio
3D cryostat design and simulation
Component Catalog
Browse all cryostat components
System Checks
Check your design for errors
Menu
physics
Interactive Course
Interactive chapters from intuition to mastery
Structured Lessons
Eight modules with formulas and self-checks
Quantum Brain
Navigate lessons, laws, gates, devices, and tools
Guided Experiments
Hands-on circuits that teach one idea each
simulator
Circuit Lab
Build circuits, run them, and see the results
Gate Reference
Quick reference for all quantum gates
wiringStudio
Cryostat Studio
3D cryostat design and simulation
Component Catalog
Browse all cryostat components
System Checks
Check your design for errors
Part of Quantum Algorithms
Home/Quantum Physics/Lessons/Deutsch’s Algorithm
{λ}

Deutsch’s Algorithm

intermediate2 qubits~12 min

The first quantum speedup — one query instead of two

The question

Can you determine a global property of a function (constant or balanced?) by evaluating it only once, when classically you need two evaluations?

Why this matters

Deutsch’s algorithm (1985, refined by Deutsch and Jozsa in 1992) was the first proof that a quantum computer can solve a specific problem strictly faster than any classical computer. The problem it solves is simple: given a black-box function f(x) on one bit, decide whether f is constant (f(0)=f(1)) or balanced (f(0)=f(1)). Classically, you must query f twice. Deutsch’s algorithm does it with one query. The speedup is modest, but the principle — encoding the answer in phase and extracting it through interference — is the blueprint for every quantum algorithm that followed.

Intuition

The trick has three parts. First, prepare a helper qubit (called the ancilla) in |−⟩ so that the oracle kicks its answer into phase rather than flipping a visible bit. Second, put the input in superposition so both f(0) and f(1) are queried simultaneously — but the result is encoded in relative phase, not in two separate answers. Third, apply Hadamard to convert the phase difference into a definite measurement outcome: ∣0⟩ means constant, ∣1⟩ means balanced.

Key insight

The oracle does not return f(x) as a bit you read. It encodes f(x) as a phase (±1) via kickback. Interference then converts the global property (constant vs balanced) into a single deterministic bit.

Circuit
Open in simulator →
q0q1XHHCXH
▶ Try it in the simulator
Step-by-step walkthrough
1

Prepare the helper qubit (ancilla) in |−⟩

Apply X then H to qubit 1. This creates |−⟩ = (∣0⟩−∣1⟩/2​, the eigenstate that enables phase kickback.

∣0⟩⊗2​∣0⟩−∣1⟩​
2

Put the input in superposition

Apply H to qubit 0. Now the input queries both x=0 and x=1 simultaneously.

2​∣0⟩+∣1⟩​⊗2​∣0⟩−∣1⟩​
3

Apply the oracle Uf​

The oracle applies f(x) via phase kickback. Each branch picks up (−1)^{f(x)}. If f is balanced, the two branches get opposite signs. If f is constant, both branches get the same sign.

2​(−1)f(0)∣0⟩+(−1)f(1)∣1⟩​⊗∣−⟩
4

Apply H to the input qubit

Hadamard converts the phase pattern into a definite computational basis state. Same phases → ∣0⟩ (constant). Opposite phases → ∣1⟩ (balanced).

∣f(0)⊕f(1)⟩⊗∣−⟩
5

Measure the input qubit

Read qubit 0. The result is f(0)⊕f(1): 0 means constant, 1 means balanced. One query determined a global property.

What the measurement tells you

Measuring ∣0⟩ on qubit 0 means f is constant (f(0)=f(1)). Measuring ∣1⟩ means f is balanced (f(0)=f(1)). The result is deterministic, not probabilistic.

Full technical statement

The oracle is a black-box gate Uf​ that encodes the function. It maps |x,y⟩ to |x, y XOR f(x)⟩, where XOR means the output bit flips if f(x)=1 and stays the same if f(x)=0. With the ancilla (helper qubit) in |−⟩, this XOR action converts into a phase via kickback: ∣x⟩|−⟩ becomes (−1)^{f(x)}∣x⟩|−⟩. When the input is in ∣+⟩ (superposition of both x=0 and x=1), both branches pick up their respective phases. If f is constant, both phases are the same, leaving ∣+⟩. If f is balanced, the phases are opposite, giving |−⟩. A final Hadamard maps ∣+⟩ to ∣0⟩ (constant) or |−⟩ to ∣1⟩ (balanced). One query gives a deterministic answer.

Classical approach

Classically, you must evaluate f(0) and f(1) separately and compare. Two queries are always required, regardless of strategy.

Quantum approach

Quantumly, superposition lets you evaluate both inputs at once, and interference converts the global property (same or different) into a single measurable bit. One query suffices.

Tempting but wrong

It is tempting to think the algorithm computes f(0) and f(1) separately and then compares them. That is not what happens. The algorithm never learns the individual values of f(0) or f(1). It determines the global property (constant vs balanced) directly through interference, without extracting either value on its own.

Where this leads

Deutsch-Jozsa generalizes this to n-bit functions: one query vs 2^{n−1}+1 classical queries. The same phase-kickback-then-interference pattern scales up to Bernstein-Vazirani, Simon’s algorithm, and eventually Shor’s factoring algorithm.

Gates you should know first
H gate →X gate →CNOT gate →
Test your understanding

In Deutsch’s algorithm, the oracle is implemented as a CNOT. What type of function does this CNOT oracle represent?

▶ Try it in the simulator↗ Nielsen and Chuang, Quantum Computation and Quantum Information↗ MIT OCW 8.06: quantum computing notes
←
Previous
Phase Kickback
Next
Quantum Teleportation
→
← Back to all lessons