Deutsch Algorithm
Track: Quantum Algorithms · Difficulty: Intermediate · Est: 12 min
Deutsch Algorithm
Overview
Deutsch’s algorithm is the first “complete” quantum algorithm many people learn.
Problem: you are given black-box access to a function
You want to decide whether is:
- constant: , or
- balanced: .
Why it’s interesting:
- Classically, in the worst case you need two queries (evaluate and ).
- Deutsch’s algorithm solves it with one oracle query (in the ideal model), using interference.
Intuition
The trick is not “computing both values at once and reading them out.” Measurement won’t let you extract both and directly.
Instead, the algorithm:
- queries the oracle in a superposition,
- encodes information about and into relative phase,
- uses interference to make the measurement outcome depend only on “same vs different.”
So the algorithm extracts a global property (constant vs balanced), not the full truth table.
Algorithm Structure
High-level steps:
- Prepare two qubits in .
- Apply H to both to create .
- Query the oracle once.
- Apply H to the first qubit.
- Measure the first qubit:
- outcome 0 means constant,
- outcome 1 means balanced.
Formal Description
Oracle model
Use the standard reversible oracle
Key preparation: the phase-kickback target
Prepare the second qubit as
If you apply to , the effect is a phase:
So after the oracle, the second qubit returns to and the function value is stored as a sign on the branch.
Interference step
Start with
Apply the oracle:
Now apply H to the first qubit. If , the two phases match and interfere into . If , they interfere into .
So measuring the first qubit tells you constant vs balanced.
Worked Example
Consider two cases.
Case A: constant function
Then , so the first-qubit state before the final H is
Applying H gives . So you measure 0 with certainty.
Case B: balanced function with
Then the state before the final H is
Applying H gives . So you measure 1 with certainty.
Turtle Tip
Deutsch’s algorithm isn’t about learning and . It’s about using one query to learn the relationship “same or different” via phase + interference.
Common Pitfalls
- Don’t say “quantum evaluates both inputs and reads both outputs.” The oracle is queried in superposition, but measurement only reveals a designed global property.
- Don’t skip the target state. It’s what turns XOR output into phase kickback.
Quick Check
- What property of does Deutsch’s algorithm decide?
- Why is preparing the second qubit in useful?
What’s Next
Deutsch’s algorithm solves the 1-bit version of a promise problem. Next we generalize the same interference idea to input bits: the Deutsch–Jozsa algorithm (constant vs balanced functions on many-bit inputs).
