Skip to content
NOUMENResearch
Network
Engineering
, home page

Two sets of ripples crossing on still water. Grover's search works by interference: waves that add up on the answer and cancel elsewhere. Generated image. Shows no real place.

Experiment 2

Find one item in sixteen in three steps.

Pick a marked item and step through the oracle and the diffusion on a four-qubit simulator.

Experiment 2Grover's searchSimulation in your browser. Not a quantum computer.

Instrument

Marked item (the one the search is looking for)
q0q1q2q3HHHHDDD

Amplitude of each item, with its sign

10.5-0.5-10123456789101112131415

Chance of finding item 11 after 0 to 8 steps (steps not yet run are left empty)

100%50%012345678
Grover's search on four simulated qubits: the circuit, the amplitude of each of the sixteen items with its sign, and the chance of finding the marked item after each step.

Reading

All sixteen items start with the same amplitude, 0.25, so each has a 6.3 percent chance. The marked item is 11.

Marked item
11 (1011 in binary)
Steps done
0
Chance of the marked item
6.3 percent
Formula
sin²((2k + 1)θ), sin θ = 1/4: 6.3 percent for k = 0
Best number of steps
3, about π/4 × √16

Your browser is not running script, so this is a finished run of the experiment.

Instrument

Marked item (the one the search is looking for)
q0q1q2q3HHHHDDDD

Amplitude of each item, with its sign

10.5-0.5-10123456789101112131415

Chance of finding item 11 after 0 to 8 steps (steps not yet run are left empty)

100%50%012345678
Grover's search on four simulated qubits: the circuit, the amplitude of each of the sixteen items with its sign, and the chance of finding the marked item after each step.

Reading

The diffusion step reflected every amplitude about their average. Item 11 is now 0.980; the others are minus 0.051. After 3 steps the chance of finding item 11 is 96.1 percent. This is the most it gets for sixteen items.

Marked item
11 (1011 in binary)
Steps done
3
Chance of the marked item
96.1 percent
Formula
sin²((2k + 1)θ), sin θ = 1/4: 96.1 percent for k = 3
Best number of steps
3, about π/4 × √16

Method

Four qubits hold an equal mix of sixteen items, each with amplitude 0.25 and so a chance of 1 in 16. One step of the search has two parts. The oracle flips the sign of the marked item's amplitude; a sign cannot be measured, so nothing visible changes yet. The diffusion step then reflects every amplitude about their average, which moves weight onto the marked item.

After k steps the chance of finding the marked item is sin²((2k + 1)θ), where sin θ is 1 over the square root of 16. That gives 47.3 percent after one step, 90.8 after two, 96.1 after three and 58.2 after four: past the best number of steps the amplitudes swing back. The page computes each of these from the state, and the reading shows the formula beside it.

The circuit

The oracle is a controlled Z on all four qubits, with open dots on the qubits where the marked item has a 0 bit. The diffusion D is Hadamard and X gates on every qubit, a controlled Z, then X and Hadamard again. That circuit gives the reflection times minus 1, a global phase that no measurement can see; the page puts it back so the signs match the usual picture.

The square root, and what it means for keys

For N items, Grover's search needs about π/4 times the square root of N steps, where checking items one by one needs about N/2 on average. Bennett, Bernstein, Brassard and Vazirani showed that no quantum algorithm can do this kind of search in fewer than about the square root of N steps, so the speed-up is a square root and no more.

Trying every key of a k bit cipher takes about 2k guesses. A square root of that is 2k/2, as if the key were half as long. NIST's FAQ adds that the full speed-up needs the steps to run one after another, not spread across many machines, and its answer is that current applications can continue to use AES with 128, 192 or 256 bit keys. Searching for an input that gives a chosen hash output is the same kind of search, with the same square-root limit.

Try it on your codeThe scanner lists the cryptography a project depends on.