This is a simulation of Grover's algorithm for searching a database for a single target address (secretly selected to be the qubit at n=
7—pretend you don't know this!). Successive applications of quantum-computer operations called inversion
increase the amplitude of the target qubit. Reading the quantum register causes collapse of its wavefunction. The probability of each possible answer is then equal to the square of its amplitude. For a database of dimension N
, the probability of locating the target is maximized after approximately
π/4 iterations. Compare this with the 50% probability for success in a classical search after N
/2 steps. Paradoxically, the quantum algorithm becomes worse
with additional iterations (actually, the probability oscillates).