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.
Deutsch algorithm
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:
∣x⟩∣y⟩→Uf→∣x⟩∣y⊕f(x)⟩
Starting on the left from two qubits ∣0⟩ and ∣1⟩,
we apply the Hadamard gateH to both:
∣0⟩∣1⟩→H⊗2→∣+⟩∣−⟩=21(∣0⟩+∣1⟩)(∣0⟩−∣1⟩)
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:
→H→(−1)f(0)∣f(0)⊕f(1)⟩
Depending on whether f is constant or balanced,
the measurement 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.
Deutsch-Jozsa algorithm
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⟩.
The oracle Uf performs this action:
Applying the N+1 Hadamard gates to the initial state
yields the following superposition:
∣0⟩⊗N∣1⟩→H⊗N+1→∣+⟩⊗N∣−⟩=2N1x=0∑2N−1∣x⟩∣−⟩
Where ∣x⟩=∣x1⟩⋯∣xN⟩ denotes a classical binary state.
For example, if x=5=20+22 in the summation,
then ∣x⟩=∣1⟩∣0⟩∣1⟩∣0⟩⊗N−3
(from least to most significant digit).
We give this state to the oracle,
and, by the same logic as for the Deutsch algorithm,
get back:
→Uf→2N1x=0∑2N−1(−1)f(x)∣x⟩∣−⟩
The last qubit ∣−⟩ is garbage.
Next, applying the Hadamard transform to the other N gives:
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:
∣c0∣2=2N1x=0∑2N−1(−1)f(x)2
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!