Deutsch’s algorithm is one of the simplest examples showing how
quantum computers can outperform classical computers — even on a very small problem.
It deals with a special kind of function:
\[ f(x): \{0,1\}^n \rightarrow \{0,1\} \]
and tries to determine whether \( f(x) \) is:
In classical computing, you would need to check more than one input to be sure which type of function it is. But Deutsch–Jozsa algorithm takes advantage of quantum parallelism — it evaluates the function for all possible inputs at once, using the principle of superposition.
Deutsch's algorithm is one of the simplest quantum algorithms, demonstrating the power of quantum parallelism and interference. It solves a specific problem—determining whether a function 𝑓(𝑥) is constant or balanced—more efficiently than any classical algorithm.
Given a function 𝑓(𝑥) where:
1. Initialize Qubits:
\( |\psi_0\rangle = |00\cdots0\rangle \otimes |1\rangle \)
\( |\psi_0\rangle = |0\rangle^{\otimes n} |1\rangle \)
2. Apply Hadamard Gates:
\( |\psi_1\rangle = H^{\otimes n} |0\rangle^{\otimes n} \, H|1\rangle \)
\( |\psi_1\rangle = H|00\cdots0\rangle \otimes H|1\rangle \)
\( |\psi_1\rangle = H|0\rangle \otimes H|0\rangle \otimes \cdots \otimes
H|0\rangle \otimes |-\rangle \)
\( |\psi_1\rangle =
\frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)
\otimes
\frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)
\otimes \cdots \otimes
\frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)
|-\rangle
\)
For Two Qubits
\( H^{\otimes 2} |0\rangle^{\otimes 2}
= \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)
\otimes
\frac{1}{\sqrt{2}} (|0\rangle + |1\rangle) \)
\( H^{\otimes 2} |0\rangle^{\otimes 2}
= \frac{1}{\sqrt{2^2}}
( |00\rangle + |01\rangle + |10\rangle + |11\rangle ) \)
\( H^{\otimes 2} |0\rangle^{\otimes 2}
= \frac{1}{\sqrt{2^2}}
\sum_{x \in \{0,1\}^2} |x\rangle \)
For Three Qubits
\( H^{\otimes 3} |0\rangle^{\otimes 3}
= \frac{1}{\sqrt{2^3}}
( |000\rangle + |001\rangle + |010\rangle + |011\rangle
+ |100\rangle + |101\rangle + |110\rangle + |111\rangle ) \)
\( H^{\otimes 3} |0\rangle^{\otimes 3}
= \frac{1}{\sqrt{2^3}}
\sum_{x \in \{0,1\}^3} |x\rangle \)
3. Apply Oracle \( U_f \)
\( |\psi_2\rangle
= U_f \frac{1}{\sqrt{2^n}}
\sum_{x \in \{0,1\}^n} |x\rangle |-\rangle \)
\( |\psi_2\rangle
= \frac{1}{\sqrt{2^n}}
\sum_{x \in \{0,1\}^n} U_f |x\rangle |-\rangle \qquad
U_f |x\rangle |-\rangle = (-1)^{f(x)} |x\rangle |-\rangle \)
\( |\psi_2\rangle
= \frac{1}{\sqrt{2^n}}
\sum_{x \in \{0,1\}^n} (-1)^{f(x)} |x\rangle |-\rangle \)
4. Apply Hadamard Gate
\( |\psi_3\rangle
= \frac{1}{\sqrt{2^n}} \sum_{x \in \{0,1\}^n}
(-1)^{f(x)} H^{\otimes n} |x\rangle |-\rangle \)
\( H^{\otimes n} |x\rangle
= H|x_0\rangle \otimes H|x_1\rangle \otimes \cdots \otimes H|x_{n-1}\rangle \)
\( H |x_i\rangle
= \frac{1}{\sqrt{2}} ( |0\rangle + (-1)^{x_i} |1\rangle ) \)
\( H|0\rangle
= \frac{1}{\sqrt{2}} ( |0\rangle + |1\rangle ) \)
\( H|1\rangle
= \frac{1}{\sqrt{2}} ( |0\rangle - |1\rangle ) \)
Testing \( H^{\otimes 3} |x\rangle \)
\( H^{\otimes 3} |x\rangle
= H|x_0\rangle \otimes H|x_1\rangle \otimes H|x_2\rangle \)
\(
= \frac{1}{\sqrt{2}} (|0\rangle + (-1)^{x_0}|1\rangle)
\otimes
\frac{1}{\sqrt{2}} (|0\rangle + (-1)^{x_1}|1\rangle)
\otimes
\frac{1}{\sqrt{2}} (|0\rangle + (-1)^{x_2}|1\rangle)
\)
\(
= \frac{1}{\sqrt{2^3}}
\sum_{z \in \{0,1\}^3}
(-1)^{x \cdot z} |z\rangle
\)
where the dot product is
\( x \cdot z = x_0 z_0 + x_1 z_1 + x_2 z_2 \).
Generalization
\(
H^{\otimes n} |x\rangle
= \frac{1}{\sqrt{2^n}}
\sum_{z \in \{0,1\}^n}
(-1)^{x \cdot z} |z\rangle
\)
Effect on \( |\psi_3\rangle \)
\(
|\psi_3\rangle
= \frac{1}{\sqrt{2^n}}
\sum_{x \in \{0,1\}^n}
(-1)^{f(x)} H^{\otimes n} |x\rangle |-\rangle
\)
\(
|\psi_3\rangle
= \frac{1}{2^n}
\sum_{x \in \{0,1\}^n}
(-1)^{f(x)}
\sum_{z \in \{0,1\}^n}
(-1)^{x \cdot z} |z\rangle |-\rangle
\)
\(
|\psi_3\rangle
= \frac{1}{2^n}
\sum_{x \in \{0,1\}^n}
\sum_{z \in \{0,1\}^n}
(-1)^{f(x) + x \cdot z} |z\rangle |-\rangle
\)