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.

Presets:

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)

000001010011100101110111mean 0.044amplitude (the sign matters)

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

  1. Put n qubits into an equal superposition, so each of the N = 2ⁿ items has amplitude 1/√N.
  2. The oracle flips the sign of the correct items. No probability changes yet.
  3. Diffusion reflects every amplitude about the mean, which boosts the flipped ones.
  4. 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.

N = 8 items, 1 marked. Exact values from sin²((2k + 1)θ).
Iterations kChance of a marked resultNote
012.5%plain guess
178.1%
294.5%best count
333.0%overshoot
41.2%overshoot
554.8%overshoot
One correct answer. Counts are checker calls and ignore the cost of the checker itself.
Items (N)Classical averageClassical, guaranteedGrover iterations
2^105131,02325
2^20524,2891,048,575804
2^30536,870,9131.07 × 10^925,735
2^405.50 × 10^111.10 × 10^12823,549
2^649.22 × 10^181.84 × 10^193.37 × 10^9
2^1281.70 × 10^383.40 × 10^381.45 × 10^19

Eight guides

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