Grover’s Algorithm Lab
Mark the answers, choose how many Grover iterations to run, and watch the amplitudes change after every oracle and diffusion step. See why the best count is about √N, what happens when you overshoot, how it compares with classical search, and how noise erodes it. Everything runs in your browser.
Reviewed December 2026. Written for learners; no maths beyond square roots and averages is needed to start.
Click items to mark or unmark them. These are the answers the oracle will recognise. Item labels are bitstrings with q0 on the left.
Chance of reading a marked item
94.5%
Best k and its chance
2 · 94.5%
Plain guessing
12.5%
Iteration 2: after diffusion (reflected about the mean)
Marked amplitude 0.972 · unmarked amplitude -0.088 · mean 0.044 · chance of a marked result 94.5%. Each amplitude was replaced by 2 × mean − amplitude.
The idea in four lines
- Put n qubits into an equal superposition, so each of the N = 2ⁿ items has amplitude 1/√N.
- The oracle flips the sign of the correct items. No probability changes yet.
- Diffusion reflects every amplitude about the mean, which boosts the flipped ones.
- Repeat about (π/4)·√N times, then measure. Check the result with the classical checker.
How to use the lab
- Try the presets first: the 4-item case is exact, the 8-item cases show the best count and an overshoot, and the half-marked case shows the trap.
- In the Amplitudes tab, move the stage slider and watch the dashed mean line. The oracle drops a bar below zero; diffusion lifts it far above the mean.
- In the Success curve tab, drag the iteration slider past the best count and see the dot move down the wave.
- In Shots and noise, raise the error per iteration to see long runs fail.
- In Code, copy the Qiskit code, or open the 2- and 3-qubit versions gate by gate in the Circuit Builder.
What the numbers look like
These tables come from the same code as the lab. Notice that with 8 items the third iteration is worse than the second.
| Iterations k | Chance of a marked result | Note |
|---|---|---|
| 0 | 12.5% | plain guess |
| 1 | 78.1% | |
| 2 | 94.5% | best count |
| 3 | 33.0% | overshoot |
| 4 | 1.2% | overshoot |
| 5 | 54.8% | overshoot |
| Items (N) | Classical average | Classical, guaranteed | Grover iterations |
|---|---|---|---|
| 2^10 | 513 | 1,023 | 25 |
| 2^20 | 524,289 | 1,048,575 | 804 |
| 2^30 | 536,870,913 | 1.07 × 10^9 | 25,735 |
| 2^40 | 5.50 × 10^11 | 1.10 × 10^12 | 823,549 |
| 2^64 | 9.22 × 10^18 | 1.84 × 10^19 | 3.37 × 10^9 |
| 2^128 | 1.70 × 10^38 | 3.40 × 10^38 | 1.45 × 10^19 |
Eight guides
How Grover’s algorithm works, step by step
9 min read
The whole algorithm in plain words: superposition, an oracle that marks the answer, a reflection that boosts it, and a measurement.
The geometry of Grover: why each iteration is a rotation
8 min read
Grover’s algorithm moves a state vector around a plane by a fixed angle each time. Seeing that picture explains the √N count and the overshoot.
How many Grover iterations should you run?
8 min read
The best count, why more is not better, and what to do when you do not know how many answers exist.
Grover with more than one correct answer
6 min read
What changes when several items are marked: a bigger starting angle, fewer iterations, and a trap when half the items are correct.
Building the oracle: the part that decides the real cost
9 min read
How a yes/no checker becomes a phase flip, how the circuit marks a bitstring, and why oracle cost matters more than the iteration count.
Grover versus classical search: the numbers
7 min read
Query counts side by side from a thousand items to a trillion, why the speedup is only quadratic, and why that is provably the best possible.
Real-world limits: when Grover’s speedup does not pay off
8 min read
Oracle cost, error correction, parallel classical hardware and the memory problem, in plain language.
Seven common mistakes about Grover’s algorithm
5 min read
The misunderstandings that show up again and again, and the correct picture for each.
Predict, then check
Work these out first, then reveal the answer and verify it in the lab.
N = 16 with one marked item. What is the best number of iterations, and how likely is success?
k = 3, success 96.1%.
N = 8 with one marked item. What happens if you run 3 iterations instead of 2?
Success falls from 94.5% to 33.0%. Three is an overshoot.
N = 4 with two marked items. How likely is success after one iteration?
50.0%, the same as a plain guess. Half the items are marked, so the algorithm cannot help.
N = 64 with four marked items. Best count, and success?
k = 3, success 96.1%.
About a million items (2^20), one marked. How many iterations?
804 iterations, success 100.000%.
What the lab does and does not do
- It computes Grover’s algorithm exactly, assuming perfect gates, with an oracle that marks the items you chose.
- The oracle “knows” the answers. That is for teaching. A real oracle is a checker circuit, and its cost is what decides whether the speedup matters.
- The noise slider is a simple model, not a model of any real machine.
- Counts of queries do not include the cost of the oracle, the cost of error correction, or the speed of the hardware.
Frequently asked questions
What does Grover’s algorithm do?
It finds an item that passes a yes/no check among N unsorted candidates using about (π/4)·√N checks, where a classical search needs about N/2 on average.
Is Grover’s algorithm exponentially faster?
No. The speedup is quadratic, and it has been proved to be the best possible for unstructured search.
Why does running more iterations make it worse?
Each iteration rotates the state by a fixed angle. After the best count the state passes the target and swings back, so the success probability falls.
Does the lab simulate a real quantum computer?
It is an exact, ideal calculation of the algorithm. Because the algorithm treats all marked items alike and all unmarked items alike, it can be computed exactly for up to 4,096 items. The noise slider is a simple teaching model.
What is the oracle?
A circuit that flips the sign of the amplitude of every correct answer. In real use it is built from a checker. In this lab the marked items are chosen by you, so the oracle is built from them.
What happens if half the items are marked?
The algorithm stops helping. With exactly half marked, a guess already succeeds half the time and each iteration lands the state back at the same probability.
Can I run the circuit in Qiskit?
Yes. The Code tab produces Qiskit source for your settings. Qiskit prints qubit 0 on the right of a result string, so reverse strings to compare with this page.
Can Grover’s algorithm break encryption?
It reduces the effective strength of symmetric keys roughly by a square root, which longer keys can offset. It is a different and smaller threat than Shor’s algorithm against public-key cryptography.
Will it speed up database searches?
Not for ordinary databases, which have indexes and cannot be loaded into a quantum computer cheaply. See the real-world limits guide.
Who invented it?
Lov Grover, then at Bell Labs, published it in 1996.
Sources and further reading
- L. K. Grover, “A fast quantum mechanical algorithm for database search” (1996). The original paper, from Bell Labs.
- C. Bennett, E. Bernstein, G. Brassard, U. Vazirani, “Strengths and weaknesses of quantum computing” (1997). Shows that no quantum algorithm can search an unstructured list in much fewer than √N queries.
- M. Boyer, G. Brassard, P. Høyer, A. Tapp, “Tight bounds on quantum searching” (1996/1998). Exact success formula, and how to search when the number of solutions is unknown.
- G. Brassard, P. Høyer, M. Mosca, A. Tapp, “Quantum amplitude amplification and estimation” (2002). The generalisation of Grover’s idea to any algorithm.
- R. Babbush et al., “Focus beyond quadratic speedups for error-corrected quantum advantage” (2021). Why a quadratic speedup is hard to turn into a practical win.
- M. Nielsen and I. Chuang, Quantum Computation and Quantum Information, chapter 6. The standard textbook treatment.