Course Home

The Deutsch Algorithm

Understanding quantum speedup through phase kickback — one qubit at a time

? The Problem

Consider a function f : {0, 1} → {0, 1} — it takes a single bit as input and outputs a single bit. There are exactly 4 possible such functions. Two are constant (same output for all inputs) and two are balanced (different outputs). Click any function below to inspect it.

The question: given a black-box oracle for f, determine whether f is constant or balanced.
Classically you need 2 queries — evaluate f(0) and f(1) then compare.
Quantum Deutsch's algorithm does it in just 1 query.

Query Complexity

Classical
2
Quantum
1
2× speedup — extends to exponential for the n-bit Deutsch-Jozsa generalization
Phase Kickback — The Key Idea

Before diving into the full algorithm, let's understand the crucial mechanism that makes it work: phase kickback. This is the trick at the heart of most quantum algorithms.

Step 1 — Prepare the ancilla in |−⟩

We prepare a special "ancilla" qubit in the state |−⟩ = (|0⟩ − |1⟩)/√2. Start with |0⟩, apply X to flip it to |1⟩, then apply H:

Step 2 — What happens when Uf acts on |x⟩|−⟩?

The oracle Uf maps |x⟩|y⟩ → |x⟩|y ⊕ f(x)⟩. Let's see what happens when the ancilla is in |−⟩:

Start with
Expand |−⟩
Apply Uf
Case f(x) = 0
Case f(x) = 1
✦ Key Result
1 / 6
The ancilla is unchanged! The phase (−1)f(x) has "kicked back" onto the input register. The ancilla is just a catalyst — it enables the phase but stays in |−⟩ throughout.

Step 3 — Interactive Phase Kickback Demo

Pick a function and an input state to see the phase kickback in action:

Step 4 — Superposition + Kickback = Interference

Now the magic: if the input is in superposition (|0⟩ + |1⟩)/√2 instead of a single basis state, phase kickback creates different phases on each branch. Then a final Hadamard gate creates interference that reveals the answer.

The Full Algorithm — Step by Step

Now let's see the complete Deutsch algorithm. Select an oracle and step through each stage to see the quantum state evolve.

or
|0⟩
Input
|0⟩
Ancilla
navigate  ·  Space auto-play  ·  R reset
Oracle Explorer

Compare all four oracles side by side. Click any function to auto-run the algorithm and see the result, or try the "Surprise Me" challenge!

Oracle f(0) f(1) After Uf After H (input) Measure Type

🎲 Surprise Me Challenge

A hidden function is loaded. Run the algorithm and predict whether it's constant or balanced!

Test Your Understanding