Grover's Algorithm Simulator
Search an unsorted list with a quantum computer: run Grover's algorithm on up to 1,024 items, see the exact success probability after every iteration, and find out why running it too long makes it fail.
Set up the search
Success probability after each iteration
The dot is your chosen number of iterations. Past the peak the probability falls again.
Show the Larzscript program that just ran
Run a calculation to see the exact program.
This is the real program the page sent to the Larzscript interpreter (compiled to WebAssembly) in your browser. The library it imports is the same code the automated tests check.
How Grover search works
Start with all N = 2n items in an equal superposition, each with amplitude 1/√N. Then repeat two steps. The oracle flips the sign of the marked item's amplitude. The diffusion step reflects every amplitude about the average. Together they rotate the state vector by an angle 2θ towards the marked item, where sin θ = 1/√N, so after k rounds the probability of finding the marked item is
Worked examples, computed above
With 16 items (4 qubits) the optimum is 3 iterations and the marked item is found with probability 96.1319% — the simulation and the formula agree to every digit shown. With 256 items it takes 12 iterations for 99.9947%; with 1,024 items, 25 iterations for 99.9461%. A classical search of 1,024 unsorted items needs 512.5 guesses on average — about 20.5 times as many.
Four items are a special case: a single iteration finds the marked item with probability exactly 1.
What is verified
The simulated success probability equals sin²((2k+1)θ) to 13 digits for eight combinations of search-space size, number of marked items and iteration count; the optimal iteration counts (1, 3 and 12 for 4, 16 and 256 items) are asserted; and overshooting is shown to reduce the probability.
Limits: the oracle is applied directly to the state vector rather than built from gates, as in every simulator; and this page searches for one marked item (the library also handles several). Simulating the 10-qubit case with its 25 iterations takes a few seconds, since it runs the full circuit.
Frequently asked questions
What does Grover's algorithm do?
It searches an unsorted list of N items for one that satisfies a condition, using about (π/4)√N quantum queries where any classical method needs about N/2 on average. It was published by Lov Grover in 1996 and is provably optimal: no quantum algorithm can do better than a quadratic speed-up for unstructured search.
Is it an exponential speed-up?
No — quadratic. Searching a million items takes about 785 quantum steps instead of 500,000 classical ones. That is a big saving, but far less dramatic than Shor's algorithm for factoring, and it needs a perfectly coherent quantum computer to realise it.
Why does running it for longer make the answer worse?
Each iteration rotates the state a fixed angle towards the target; after the optimal number it overshoots and swings away again. On 16 items the optimum is 3 iterations giving 96.13%; running 6 drops the success probability to 2.038%. The plot shows the whole oscillation.
Is the plot simulated or calculated?
The number printed as 'simulated' comes from actually running the circuit — Hadamards, oracle and diffusion on the full 2n-amplitude state vector. The curve uses the exact closed form sin²((2k+1)θ), with θ = arcsin(1/√N); the library's tests confirm the simulation and the formula agree to 13 digits, so the curve is the same result without simulating every point.
What is the 'oracle'?
A black box that flips the sign of the amplitude of the marked item and leaves the others alone. In a real application it would compute your search condition in superposition. Here it is applied directly to the state vector, which is what simulators do.
Every number on this page is computed by the open-source larzscript-cosmos library (qalgo, quantum, physmath), written in Larzscript, and checked against independent references in its test suite. How it is verified →