The Deutsch-Jozsa algorithm, introduced by David Deutsch and Richard Jozsa in their 1992 paper Rapid solution of problems by quantum computation, marked an important early milestone in the development of quantum algorithms. The formulation familiar to us today—featuring the standard quantum circuit model and oracle—was later refined in 1998 by Richard Cleve, Artur Ekert, Chiara Macchiavello, and Michele Mosca in their paper Quantum algorithms revisited. Both papers are highly readable, and we encourage interested readers to consult them directly.
As a deterministic quantum algorithm, the Deutsch-Jozsa algorithm has limited direct practical applications. Its significance lies in demonstrating, for the first time, that quantum computation can achieve an exponential speedup over all deterministic classical algorithms. Studying this algorithm offers valuable insight into how quantum algorithms are structured and why they can outperform classical methods.
It is worth noting that this exponential separation holds only when compared with deterministic classical algorithms. If classical randomness is allowed, such an exponential advantage no longer appears. The first quantum algorithm to establish an exponential speedup over any classical stochastic algorithm is Simon’s algorithm, see this post.
Definition (Problem of the Deutsch-Jozsa Algorithm). Consider a function
that accepts -bit binary inputs and outputs either 0 or 1. It is guaranteed that
is either constant (producing the same output for all inputs) or balanced (outputting 1 for exactly half of the inputs and
for the other half). The objective is to determine whether
is constant or balanced by querying the oracle.
For example, consider a one-bit input function . The function is constant if
, and balanced if
(equivalently,
, where
denotes addition modulo 2). Determining whether
is constant or balanced is thus equivalent to evaluating
. This can also be viewed as a quantum XOR game: if the result is 0, then
is constant; otherwise,
is balanced.
Deutsch-Jozsa Algorithm: n=1 Case
Let us begin with the simplest example, namely the case of the Deutsch-Jozsa algorithm, to gain some intuition about how quantum algorithms work.
Classically, we would need to evaluate twice to solve the problem, namely compute
and
. There is no way around this. Quantum mechanically, we can do better. To begin, we need to “promote” the function
to a unitary operation
, defined by
We do not concern ourselves here with how to implement in an actual quantum circuit. Instead, we treat it as a black box that can be used freely. Such a black box is called a quantum oracle, and we will encounter this concept frequently in many other quantum algorithms, like Simon’s algorithm, Grover search algorith, Shor’s algorithm, etc.
Exercise. As a simple practice, prove that defined above is a unitary operator for both balanced and constant functions
.
Proof. Consider the action of on the four computational basis states:
Notice that regardless of the value of
, and similarly
.
Hence, the images of the basis states under form an orthonormal basis, which shows that
is indeed unitary. ∎
With the quantum oracle , the Deutsch-Jozsa algorithm works as follows.
We prepare two qubits: one for the input of and one for the output. They are initialized in the state
. Then we perform the following steps:
- Apply Hadamard gates to both qubits:
.
- Apply the oracle:
.
- Apply a Hadamard gate to the first qubit:
.
- Measure the first qubit in the computational basis.
Let us examine what happens step by step. After steps 1 and 2, we obtain
Next, we use a simple but important trick: we rewrite the action of the oracle so that the value of appears as a phase. The key identity is
valid for . The state after applying the oracle can be rewritten as
Ignoring the second qubit and the global phase, the first qubit is in the state
Our goal is to determine , which is encoded in the relative phase
of the first qubit. To read out this information, we apply a Hadamard gate to the first qubit and then measure it in the computational basis. This is an example of an interferometric measurement scheme, a standard method for extracting the coefficient of a state in a given basis; you will encounter this technique in many other contexts as well.
After applying the Hadamard, the state of the first qubit becomes
The probabilities of measuring the first qubit in the computational basis are then
Hence, if (the function is constant), we will certainly measure
.
If (the function is balanced), we will measure
.
In other words, a single query to the quantum oracle suffices to determine with certainty whether is constant or balanced. In contrast, a classical algorithm would require evaluating
twice.
The key mechanism at work here is quantum parallelism: in step 2, the oracle evaluates ff f across both inputs in parallel, storing the outcomes in superposition. The concluding Hadamard transformation then translates this superposed information into observable probability amplitudes, from which we can efficiently determine the answer.
Deutsch-Jozsa Algorithm
Now let us turn to the general case in which has an
-bit input. As in the
case, the classical oracle must be replaced by a quantum oracle
that coherently evaluates the function. By definition, the quantum oracle acts as
where is an
-bit string, and we write
This means we use the canonical encoding that maps each bit string to a corresponding computational basis state.
Exercise. Prove that the quantum oracle defined by
is unitary.
Proof. The operator permutes the computational basis states. Indeed, for each basis vector
the image
is again a computational-basis vector, and distinct input basis vectors have distinct images because
is a bijection on ${0,1}$. Hence the set of images of the computational basis is another orthonormal basis of the Hilbert space. A linear map that sends an orthonormal basis to an orthonormal basis preserves inner products and therefore is unitary. Thus
is unitary (Equivalently, one can note that
since
, so
is invertible with
, and a permutation matrix with real entries has its inverse equal to its adjoint; either way
is unitary.) ∎
The quantum circuit for the Deutsch–Jozsa algorithm is shown in Figure 3. The algorithm proceeds as follows:
- Initial State: Prepare an n-qubit input register in the state
and a single output qubit in the state
:
.
- Hadamard Transform: Apply the Hadamard gate to each qubit:
.
- Oracle Query: Apply the quantum oracle
:
.
After applying the oracle, the state becomes,
using the identity.
The output qubit is no longer entangled with the input register, so we can ignore it, leaving.
- Second Hadamard Transform: Apply
to the input register:
,
giving.
- Measurement: Measure the n-qubit input register. The outcome reveals the type of function:
- If
is constant, interference ensures only
appears.
- If
is balanced, destructive interference prevents
from appearing.
Measuring indicates a constant function; any other outcome indicates a balanced function.
Exercise: Verify that the states at each step of the n-qubit Deutsch-Jozsa algorithm match the evolution described above for a given function .
Classically, if we want to solve the problem by brute force, we need to check about half of the inputs, thus evaluating up to
times in the worst case. The Deutsch-Jozsa algorithm solves the problem with only one evaluation of the oracle, compared to the exponentially growing number of evaluations required by a classical algorithm. The quantum algorithm achieves this exponential speedup by leveraging quantum superposition and interference.



