Deutsch–Jozsa Algorithm
Track: Quantum Algorithms · Difficulty: Intermediate · Est: 15 min
Deutsch–Jozsa Algorithm
Overview
Deutsch–Jozsa is the multi-bit generalization of Deutsch’s algorithm.
You’re given oracle access to a function
with a promise that is either:
- constant: same output for all inputs, or
- balanced: outputs 0 on exactly half of inputs and 1 on exactly half.
Goal: decide which case holds.
Why it’s interesting:
- Classically, to be sure in the worst case you may need many queries.
- Deutsch–Jozsa solves it with one oracle query (ideal model), by encoding the global property into interference.
Intuition
The algorithm queries the oracle on a uniform superposition of all inputs.
-
If is constant, the oracle applies the same phase to every branch. That global phase does not affect measurement, so the “uniform structure” remains.
-
If is balanced, half the branches get a phase flip and half do not. That pattern causes destructive interference in a very specific place.
After a final mixing step (Hadamards), the measurement outcome is designed to be:
- all zeros if constant,
- anything else if balanced.
This is a clean demonstration of “global property extraction via phase patterns.”
Algorithm Structure
High-level steps:
- Prepare input qubits in and one target qubit in .
- Apply H to all qubits to create a uniform superposition on the input and on the target.
- Query the oracle once.
- Apply H to the input register.
- Measure the input register:
- if you get , conclude constant;
- otherwise, conclude balanced.
Formal Description
Oracle
Use the reversible oracle
Create the uniform query
After applying H to the input qubits:
Prepare the target as (via H on ). Then querying produces phase kickback:
So the entire function is now a pattern of signs across the input superposition.
Why the final Hadamards work
Applying mixes all branches. The amplitude of the outcome becomes proportional to the sum of those signs.
- If is constant, all signs match, the sum is large, and appears with certainty.
- If is balanced, half are +1 and half are −1, the sum cancels, and has zero amplitude.
This is interference doing global counting without enumerating outputs one-by-one.
Worked Example
Take . The input superposition is over .
Constant example: for all
Then for all branches. After the oracle, the input register is still the uniform superposition. The final maps that uniform state to . So you measure with certainty.
Balanced example:
This function is 0 on two inputs and 1 on two inputs. The oracle applies a sign pattern with two + and two −. The final causes cancellation specifically at . So you will never measure .
Turtle Tip
Deutsch–Jozsa is a “phase-pattern test.” Constant means all phases align; balanced means perfect cancellation for the all-zero outcome.
Common Pitfalls
- Don’t drop the promise. The algorithm is designed for the promise “constant or balanced,” not arbitrary functions.
- Don’t interpret the single query as “learning all outputs.” It learns a global property via interference.
Quick Check
- What measurement outcome indicates a constant function in Deutsch–Jozsa?
- Why does a balanced function cause cancellation at ?
What’s Next
Deutsch–Jozsa decides a global promise property. Next we study Bernstein–Vazirani, where the oracle hides a specific bitstring and phase kickback lets you recover it in a single query.
