← Quantum Information & Computing
🧩

Deutsch-Jozsa & Bernstein-Vazirani

The Deutsch-Jozsa algorithm was the first algorithm to demonstrate an exponential quantum speedup — albeit for a contrived problem. It determines in one query whether a hidden Boolean function is constant or balanced, whereas classical deterministic algorithms may need exponentially many. Bernstein-Vazirani finds a hidden bit string in one query versus n classical queries, giving a concrete polynomial speedup.

Key Concepts

Oracle Model
Algorithms access a function ff only through an oracle (black box) Ufxy=xyf(x)U_f|x\rangle|y\rangle = |x\rangle|y \oplus f(x)\rangle that computes f(x)f(x) without revealing its implementation. Query complexity counts oracle calls, not arithmetic. Quantum algorithms can query ff in superposition — evaluating all inputs simultaneously.
Constant vs Balanced Functions
A function f:{0,1}n{0,1}f:\{0,1\}^n \to \{0,1\} is constant if f(x)=cf(x) = c for all xx (either all 0 or all 1), or balanced if exactly half the inputs map to 0 and half to 1. Deutsch-Jozsa distinguishes these two cases with a guarantee that the function is one or the other.
Deutsch-Jozsa Algorithm
Prepare nn input qubits in 0n|0\rangle^{\otimes n} and one ancilla in |{-}\rangle. Apply HnH^{\otimes n} to create equal superposition, then query the oracle once, then apply HnH^{\otimes n} again. Measure the input register: outcome 0n|0\rangle^{\otimes n} means constant; any other outcome means balanced. One query suffices.
Bernstein-Vazirani Problem
Given oracle for f(x)=sxmod2f(x) = s \cdot x \bmod 2 (bitwise dot product with hidden string ss), find ss. Quantum: prepare superposition, query oracle once, apply HnH^{\otimes n}, measure — output is exactly ss. Classical: need nn queries (one per bit of ss). Quantum advantage: factor of nn.
Query Complexity Separation
Deutsch-Jozsa proves an exponential separation between quantum and classical deterministic query complexity: Q(f)=1Q(f) = 1 vs D(f)=2n1+1D(f) = 2^{n-1}+1. While not a practical speedup (randomized classical algorithms solve it in 2 queries), it was the first proof that quantum computers can be exponentially faster in the query model.

Key Equations

Oracle Action
Ufxy=xyf(x)U_f|x\rangle|y\rangle = |x\rangle|y \oplus f(x)\rangle
The quantum oracle computes f(x) into an ancilla qubit without measuring x.
Phase Kickback
Ufx=(1)f(x)xU_f|x\rangle|{-}\rangle = (-1)^{f(x)}|x\rangle|{-}\rangle
With ancilla in |−⟩, the oracle imprints f(x) as a phase on |x⟩ — the phase kickback trick.
Deutsch-Jozsa After Oracle
Hn(x(1)f(x)x)={0nf constant0nf balancedH^{\otimes n}\left(\sum_x (-1)^{f(x)}|x\rangle\right) = \begin{cases} |0^n\rangle & f \text{ constant}\\ \perp |0^n\rangle & f \text{ balanced}\end{cases}
Constructive/destructive interference reveals the function type in one measurement.
Bernstein-Vazirani Output
HnUfHn0n=sH^{\otimes n} \cdot U_f \cdot H^{\otimes n} |0^n\rangle = |s\rangle
One oracle query reveals the full n-bit hidden string s.
Worked Example

Deutsch's Algorithm (n=1)

Problem

For n=1n=1, Deutsch's algorithm determines if f:{0,1}{0,1}f:\{0,1\}\to\{0,1\} is constant or balanced with one query. Trace through it for a balanced function with f(0)=0,f(1)=1f(0)=0, f(1)=1.

Solution

Start with 01|01\rangle (input qubit 0, ancilla qubit 1). Apply HHH\otimes H:

+=12(0+1)12(01)|{+}\rangle|{-}\rangle = \frac{1}{\sqrt{2}}(|0\rangle+|1\rangle)\cdot\frac{1}{\sqrt{2}}(|0\rangle-|1\rangle)

Apply oracle UfU_f. Phase kickback gives (1)f(x)(-1)^{f(x)} on each term:

12[(1)f(0)0+(1)f(1)1]=12[01]=\frac{1}{\sqrt{2}}[(-1)^{f(0)}|0\rangle + (-1)^{f(1)}|1\rangle]|{-}\rangle = \frac{1}{\sqrt{2}}[|0\rangle - |1\rangle]|{-}\rangle = |{-}\rangle|{-}\rangle

Apply HH to input: H=1H|{-}\rangle = |1\rangle.

Measuring 1|1\rangle (not 0|0\rangle) indicates the function is balanced.

Answer Measurement outcome |1⟩ → balanced function. One oracle query sufficed.
Practice

Exercises

5 problems
1 of 5

Deutsch-Jozsa uses 1 quantum query. Classical deterministic worst case for n=3n=3 input bits requires 2n1+12^{n-1}+1 queries. How many?

queries
2 of 5

Quantum Deutsch-Jozsa speedup ratio (classical/quantum queries) for any nn: quantum=1, classical=2n1+12^{n-1}+1. For n=10n=10, how many classical queries are needed?

queries
3 of 5

A balanced f:{0,1}3{0,1}f:\{0,1\}^3\to\{0,1\} has exactly half of 23=82^3=8 inputs mapping to 1. How many inputs map to 1?

Unlock Exercise 3

Subscribe to PhysWeb Pro to access all exercises and track your progress.

Upgrade to Pro →
4 of 5

Bernstein-Vazirani recovers a n=128n=128 bit string with 1 quantum query. Classical needs n=128n=128 queries. Quantum savings?

Unlock Exercise 4

Subscribe to PhysWeb Pro to access all exercises and track your progress.

Upgrade to Pro →
5 of 5

For a constant function in Deutsch-Jozsa, the probability of measuring all-zeros 0n|0^n\rangle is:

Unlock Exercise 5

Subscribe to PhysWeb Pro to access all exercises and track your progress.

Upgrade to Pro →

Key Takeaways

  • The oracle Ufxy=xyf(x)U_f|x\rangle|y\rangle = |x\rangle|y\oplus f(x)\rangle enables superposition queries — evaluating ff on all inputs at once.
  • Phase kickback: using ancilla |{-}\rangle converts oracle action to phase (1)f(x)(-1)^{f(x)} on x|x\rangle.
  • Deutsch-Jozsa distinguishes constant from balanced ff in 1 query; classical deterministic needs 2n1+12^{n-1}+1.
  • Bernstein-Vazirani recovers the full nn-bit hidden string ss in 1 query; classical needs nn.
  • Both algorithms use the same circuit template: HnUfHnH^{\otimes n} \to U_f \to H^{\otimes n} \to measure.