Deutsch’s Algorithm
1. Problem Statement
Deutsch’s algorithm is used to solve the parity problem: Parity \(= f(0) \oplus f(1)\). Here, \(\oplus\) denotes the XOR operator. For example:
\(f(0) = f(1)\), Parity \(= 0\) (even parity, constant function)
\(f(0) \neq f(1)\), Parity \(= 1\) (odd parity, balanced function)
2. Quantum Solution

The circuit starts with:
After the Hadamard gate is applied, it transforms \(\ket{0} \to \ket{+}\) and \(\ket{1} \to \ket{-}\). Therefore, \(\ket{\psi_0} = \ket{+-}\). To simplify, rewrite the plus state and distribute the negative state:
Now, query the oracle \(U_f\).
As per definition of phase oracles: \(U_f\ket{x}\ket{-} = (-1)^{f(x)}=\ket{x}\ket{-}\), plug it into the equation:
Back to the parity equation:
Applying last Hadamard gate flips the plus state to zero, and minus state to one:
Finally, we measure the first qubit. This matches the parity problem, where:
If we measure 0, then the function is constant: \(f(0) = f(1)\)
If we measure 1, then the function is constant: \(f(0) \neq f(1)\)