← 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) Uf∣x⟩∣y⟩=∣x⟩∣yβŠ•f(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 ∣0βŸ©βŠ—n|0\rangle^{\otimes n} and one ancilla in βˆ£βˆ’βŸ©|{-}\rangle. Apply HβŠ—nH^{\otimes n} to create equal superposition, then query the oracle once, then apply HβŠ—nH^{\otimes n} again. Measure the input register: outcome ∣0βŸ©βŠ—n|0\rangle^{\otimes n} means constant; any other outcome means balanced. One query suffices.
Bernstein-Vazirani Problem
Given oracle for f(x)=sβ‹…xβ€Šmodβ€Š2f(x) = s \cdot x \bmod 2 (bitwise dot product with hidden string ss), find ss. Quantum: prepare superposition, query oracle once, apply HβŠ—nH^{\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)=2nβˆ’1+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
Uf∣x⟩∣y⟩=∣x⟩∣yβŠ•f(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
Uf∣xβŸ©βˆ£βˆ’βŸ©=(βˆ’1)f(x)∣xβŸ©βˆ£βˆ’βŸ©U_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
HβŠ—n(βˆ‘x(βˆ’1)f(x)∣x⟩)={∣0n⟩fΒ constantβŠ₯∣0n⟩fΒ 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
HβŠ—nβ‹…Ufβ‹…HβŠ—n∣0n⟩=∣s⟩H^{\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 HβŠ—HH\otimes H:

∣+βŸ©βˆ£βˆ’βŸ©=12(∣0⟩+∣1⟩)β‹…12(∣0βŸ©βˆ’βˆ£1⟩)|{+}\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[∣0βŸ©βˆ’βˆ£1⟩]βˆ£βˆ’βŸ©=βˆ£βˆ’βŸ©βˆ£βˆ’βŸ©\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βˆ£βˆ’βŸ©=∣1⟩H|{-}\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 2nβˆ’1+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=2nβˆ’1+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 Uf∣x⟩∣y⟩=∣x⟩∣yβŠ•f(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 2nβˆ’1+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: HβŠ—nβ†’Ufβ†’HβŠ—nβ†’H^{\otimes n} \to U_f \to H^{\otimes n} \to measure.