Input. The phase oracle on qubits; the number of solutions.
Procedure. Let satisfy and .
- Prepare .
- Repeat times: apply , then the diffusion operator .
- Measure in the computational basis and output the result (optionally check with one more query).
Guarantee. With and the projector onto marked strings, and is the operator of amplitude amplification (the sign convention gives exactly ). Hence after iterations the probability of measuring a marked string is , and for the chosen it is at least . The number of oracle queries is .
Cost. oracle calls plus diffusion steps; each diffusion is two layers of Hadamards and a reflection about , which is an -controlled conjugated by gates: elementary gates with ancillas. Total queries and further gates.
Remarks. If is unknown, running with a random number of iterations drawn from a range that grows geometrically finds a solution in expected queries (Boyer, Brassard, Høyer and Tapp). Iterating past is harmful: the probability oscillates with period about iterations.
The algorithm is due to Grover; the exact analysis with is from Boyer, Brassard, Høyer and Tapp, and section 6.1 of Nielsen and Chuang gives a textbook account.