The Deutsch algorithm and its extension, the Deutsch-Jozsa algorithm,
were first to prove that quantum computers can
solve certain problems more efficiently
than any classical system.
Given an unknown “black box” binary function f(x) of one or more bits x,
the goal is determine whether f is
constant (i.e. f(x) is the same for all x)
or balanced (i.e. exactly 50% of all x-values yield f(x)=0,
and the other 50% yield f(x)=1).
We can query f as many times as we want with inputs of our choice,
but we want to solve the problem using as few queries as possible.
The problem is extremely artificial and of no practical use,
but quantum computers can solve it with a single query,
while classical computers need up to 2N−1+1 queries
for an N-bit x.
The Deutsch algorithm handles the simplest case,
where x is only a single bit.
Only four f exist:
Constant: (f(0)=f(1)=0) or (f(0)=f(1)=1).
Balanced: (f(0)=0,f(1)=1), or (f(0)=1,f(1)=0).
In other words, we only need to determine if f(0)=f(1) or f(0)=f(1).
To do this, we use the following quantum circuit,
where Uf is the oracle we query:
Due to unitarity constraints,
the action of Uf is defined to be as follows,
with ⊕ meaning XOR:
Starting on the left from two qubits ∣0⟩ and ∣1⟩,
we apply the Hadamard gateH to both:
Feeding this result into the oracle Uf then leads us to:
If f is constant, then f(0)⊕f(1)=0,
meaning this state is (−1)f(0)∣+⟩.
On the other hand, if f is balanced, then f(0)⊕f(1)=1,
meaning this state is (−1)f(0)∣−⟩.
Taking the Hadamard transform of this qubit therefore yields:
Depending on whether f is constant or balanced,
the mearurement outcome of this state will be ∣0⟩ or ∣1⟩
with 100\% probability. We have solved the problem!
Note that we only consulted the oracle (i.e. applied Uf) once.
A classical computer would need to query it twice,
once with input x=0, and again with x=1.
The Deutsch-Jozsa algorithm generalizes the above to N-bit inputs x.
We are promised that f(x) is either constant or balanced;
other possibilities are assumed to be impossible.
This algorithm is then implemented by the following quantum circuit:
There are N qubits in initial state ∣0⟩, and one in ∣1⟩.
For clarity, the oracle Uf works like so:
Where x⋅y is the bitwise dot product of the binary representations of x and y,
so, for example, if N=2, then x⋅y=x1y1+x2y2.
Note that the above expression has not been reduced at all;
it follows from the definition of the Hadamard transform.
We can rewrite it like so:
The parenthesized expression can be interpreted as the coefficients
of a superposition of several y-values.
Therefore, the probability that a measurement yields y=0,
i.e. ∣y⟩=∣0⟩⊗N, is:
The summation always contains an even number of terms, for all values of N.
Consequently, if f is constant, then ∣c0∣2=∣±2N/2N∣2=1.
Otherwise, if f is balanced, all the terms cancel out, so we are left with ∣c0∣2=0.
In other words, we reach the same result as the Deutsch algorithm:
we only need to measure the N qubits once;
f is constant if and only if all are zero.
The Deutsch-Jozsa algorithm needs only one oracle query to give an error-free result,
whereas a classical computer needs 2N−1+1 queries in the worst case;
a revolutionary discovery.