QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
01 · Deutsch–Jozsa: one query instead of many0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 202Quantum Algorithms·Lesson 1 of 5

Deutsch–Jozsa: one query instead of many

The first algorithm with a provable gap: is a function constant or balanced?

Intermediate14 min read4 sections · 2 questions+45
By the end you will be able to
  1. 01Explain the oracle model and phase kickback.
  2. 02Predict the output of Deutsch–Jozsa for a constant and a balanced oracle.
  3. 03Say honestly why the speed-up is a toy.

You are given a black box computing f: {0,1}ⁿ → {0,1} and promised that f is either constant (same output for every input) or balanced (0 on exactly half the inputs). Classically, you may need 2ⁿ⁻¹ + 1 queries to be sure. Deutsch–Jozsa needs one.

Uf​∣x⟩∣−⟩=(−1)f(x)∣x⟩∣−⟩
Phase kickback: with the target in |−⟩, the oracle writes f(x) into the phase of |x⟩ instead of into the target bit. Interference can now read all those phases at once.
  • H on every input qubit: uniform superposition over all x.
  • Oracle: phases (−1)^{f(x)}.
  • H again: the amplitude of |0…0⟩ becomes the average of (−1)^{f(x)}: ±1 if constant, exactly 0 if balanced.
  • Measure: all zeros means constant, anything else means balanced.
Hands-on

Balanced oracle on 3 qubits

The oracle is f(x) = x0 ⊕ x2 (two CNOTs onto the target). Simulate: the three input bits are never 000. Replace the two CNOTs by nothing (constant f = 0) and the result is always 000.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[4] q;
bit[3] c;
x q[3];
h q[0];
h q[1];
h q[2];
h q[3];
barrier q;
cx q[0], q[3];
cx q[2], q[3];
barrier q;
h q[0];
h q[1];
h q[2];
c[0] = measure q[0];
c[1] = measure q[1];
c[2] = measure q[2];
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground

Be honest about the gap: the classical cost is exponential only if you insist on certainty. A randomised classical algorithm with a few queries is almost always right. Deutsch–Jozsa matters because it is the clearest demonstration of interference doing work, and because its structure returns in Bernstein–Vazirani, Simon and Shor.

Knowledge check

2 questions · one try each counts

Question 1

Why is the target qubit prepared in |−⟩ rather than |0⟩?

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

For a balanced oracle the probability of measuring 0…0 is…

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

Deutsch–Jozsa writes f into phases with kickback and reads them all with one round of interference. One query decides constant versus balanced.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 2 · 10 min
Bernstein–Vazirani: read a hidden string
Same circuit shape, more useful result: recover an n-bit secret with one query.
Further reading
  • Docs: algorithm walkthroughs
More in Quantum Algorithms
  • Grover's search
  • QFT and phase estimation
  • Shor's algorithm: the overview
Teleportation with feed-forwardBernstein–Vazirani: read a hidden string
In this lesson0%
  1. Introduction
  2. Try it: Balanced oracle on 3 qubits
  3. Knowledge check
  4. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in