Many computing problems come down to search: among a huge number of candidates, find the one that satisfies a condition. If the candidates have no structure to exploit, a classical computer can do no better than check them one after another. Grover’s algorithm shows that a quantum computer can manage with far fewer checks, although the gain is smaller than popular accounts suggest.

What does Grover’s algorithm do?

Lov Grover published the algorithm in 1996, while working at Bell Labs. The task it addresses is called unstructured search: there are N candidates and a test that tells whether a given candidate is correct, but no hint about where the correct one is. Classically this takes about N/2 tests on average. Grover’s algorithm needs roughly √N steps. For a million candidates that means on the order of a thousand steps.

This is called a quadratic speed-up. It is substantial, but it is not in the same class as the exponential speed-up of Shor’s algorithm. It has also been proven that no quantum algorithm can do unstructured search in fewer than about √N steps.

How does Grover’s algorithm work?

The method is known as amplitude amplification. A quantum register in superposition assigns an amplitude to every candidate, and the probability of measuring a candidate is the squared magnitude of its amplitude. The algorithm reshapes these amplitudes step by step:

  1. Start with an equal superposition of all N candidates. Every candidate has the same small amplitude, so measuring now would return a random one.
  2. Apply the test, called the oracle, to the whole superposition. It does not reveal the answer; it only flips the sign of the amplitude of the correct candidate.
  3. Apply a second operation, usually described as a reflection about the average. Because the marked amplitude now lies below the average, the reflection raises it and slightly lowers all the others.
  4. Repeat steps 2 and 3 about √N times, then measure. The correct candidate now appears with high probability.

It resembles pushing someone on a swing: each small push at the right moment adds a little to the motion. The comparison fails in one respect: an extra push on a swing does no harm, whereas here too many repetitions make the probability of success fall again.

The algorithm does not look at all candidates at once and read off the answer. A measurement yields a single outcome, and the interference built up over the rounds is what makes it the useful one.

What does it mean for cryptography?

Guessing a secret key is an unstructured search. A symmetric cipher with an n-bit key has 2ⁿ possible keys, and Grover’s algorithm reduces the search to about the square root of that number of cipher evaluations. In effect the key length is halved:

Algorithm Classical key search With Grover’s algorithm
AES-128 about 2¹²⁸ steps about 2⁶⁴ steps
AES-256 about 2²⁵⁶ steps about 2¹²⁸ steps

This is why 256-bit keys are recommended for data that needs long-term protection: even after halving, a 128-bit margin remains. Hash functions are affected in a similar way when an attacker searches for an input that produces a given output, and outputs of 256 bits or more keep a comfortable margin.

Public-key cryptography is a separate matter. RSA and elliptic-curve schemes fall to Shor’s algorithm, and longer keys do not help there; they have to be replaced by post-quantum cryptography.

What are the limits of Grover’s algorithm?

The √N figure counts steps, not seconds. Several factors reduce the practical gain:

  • Error-correction overhead: each step runs the test, for example a complete AES encryption, as a quantum circuit on logical qubits protected by quantum error correction. Such operations are expected to be far slower and costlier than classical ones.
  • Poor parallelisation: the rounds have to run one after another. Splitting the search across K quantum computers shortens the running time only by a factor of √K, far less than a classical search would gain.
  • The need for an oracle: the test must be a circuit that can run in superposition. Data in a classical database would first have to be loaded, at a cost proportional to its size.

For these reasons Grover’s algorithm is regarded as a much smaller practical threat to cryptography than Shor’s algorithm.

Where else is Grover’s algorithm used?

Its lasting importance is as a building block. Amplitude amplification generalises Grover’s idea to any quantum procedure that succeeds with some probability, raising that probability quadratically faster than simple repetition would. The related technique of amplitude estimation underlies proposed quantum speed-ups for Monte Carlo simulation, and Grover-style search appears as a subroutine in quantum algorithms for optimisation and other search problems. In every case the gain is quadratic, and whether it survives the overhead of fault-tolerant hardware has to be assessed case by case.

How Q&Co can help

Q&Co designs and implements quantum algorithms tailored to specific industries, and checks first whether a problem is suited to quantum computing at all. To discuss a use case or your post-quantum security plans, contact us.