Algorithms

Deutsch-Jozsa Algorithm

An early quantum algorithm that decides whether a hidden function is constant or balanced with a single query.

Definition

The Deutsch-Jozsa algorithm is a quantum algorithm that determines whether a function f from n bits to one bit is constant, returning the same value for every input, or balanced, returning 0 for exactly half the inputs and 1 for the other half, using a single query to f. A deterministic classical algorithm may need up to 2^(n−1) + 1 queries.

In depth

For two input bits, take the balanced function f(x0, x1) = x0 XOR x1. The circuit puts the ancilla in the minus state, applies Hadamards to the inputs, applies one CNOT from each input to the ancilla, and applies Hadamards again. The inputs read 11 every time. For the constant function f = 0, the oracle does nothing, the two layers of Hadamards cancel, and the inputs read 00. One run distinguishes the cases with certainty. You can run both circuits in the interactive widgets in our superposition lesson.

The classical comparison deserves care. A deterministic classical algorithm must be sure, so in the worst case it queries more than half the inputs, which is 2^(n−1) + 1. A randomised classical algorithm that accepts a small chance of error needs only a few queries, because a balanced function is unlikely to look constant on several random inputs. So the exponential separation is between quantum and deterministic classical, not between quantum and all classical methods.

The algorithm matters because it introduces the pattern used by later, more significant algorithms: create a uniform superposition, use an oracle to write information into phases, and use interference to turn the phases into a measurement result. Bernstein-Vazirani, Simon's algorithm and Shor's algorithm all follow that script.

Technical Definition

The circuit prepares n input qubits in |0⟩ and one ancilla in |1⟩, applies Hadamard gates to all of them, calls the oracle once, and applies Hadamards to the input qubits again. Phase kickback turns the oracle into a sign flip (−1)^f(x) on the inputs. Measuring the inputs gives all zeros if f is constant, and any other result if f is balanced.

Visual Explanation: An Analogy

Imagine a room of 1,000 light switches and a rule that the lights are either all the same or exactly half on. A classical checker must test switches one by one until it finds two that differ, which can take over 500 checks. The quantum method listens to all switches at once and hears either complete agreement or a clash.

Key facts

ItemDetail
PublishedDavid Deutsch and Richard Jozsa, 1992
Queries1 quantum versus up to 2^(n−1) + 1 deterministic classical
ProblemConstant versus balanced function
NeedsOne oracle call and an ancilla in the minus state

Where the idea comes from

Deutsch described a one-bit version in 1985, and in 1992 Deutsch and Jozsa generalised it to n bits. A later improvement by Cleve, Ekert, Macchiavello and Mosca in 1998 gave the version taught today.

Real-World Use Cases

  • Teaching the idea of quantum parallelism and interference
  • Demonstrating a proven quantum-versus-deterministic-classical separation
  • Serving as a stepping stone to Bernstein-Vazirani and Simon's algorithm

How it differs from related ideas

  • Compared with Bernstein-Vazirani, which finds a hidden bit string with one query, Deutsch-Jozsa only decides a yes-or-no property.
  • Compared with Grover's algorithm, it uses interference for an exact answer on a promise problem, not an amplitude boost for a search.

Common Misconceptions

  • The speed-up is against deterministic classical algorithms only. A randomised classical algorithm solves the problem with a handful of queries and a tiny error probability.
  • The problem is artificial. Deutsch-Jozsa is valued for its lesson, not for a practical application.

Frequently asked questions

What does the algorithm output for a balanced function?

Any non-zero string on the input qubits, and for the XOR example above exactly 11.

Is it faster than every classical method?

No. A randomised classical algorithm solves it with very few queries.

Why does it matter?

It was among the first proofs that a quantum computer can do something provably faster than a deterministic classical one.

Related Terms

Learn it in a lesson

← Back to the dictionary