Quantum Algorithms Database

Grover's Algorithm

Searches unsorted data in roughly √N steps instead of N, using amplitude amplification.

Last reviewed September 30, 2026. Check the linked sources for anything that may have changed since.

Year

1996 (conference); 1997 (journal)

Inventor(s)

Lov Grover

Speedup Type

Quadratic Speedup

Difficulty

★★★☆☆

Overview

Grover's algorithm searches an unsorted collection of N items for one that satisfies a condition, using about the square root of N queries instead of the roughly N a classical computer needs. The speedup is quadratic, and unlike Shor's, it applies to a very broad class of problems: anything where you can check a candidate answer quickly but have no shortcut for finding it.

It is also provably optimal. Bennett, Bernstein, Brassard, and Vazirani showed in 1997 that no quantum algorithm can search an unstructured list in fewer than about the square root of N queries. That makes Grover's algorithm a clean example of how far quantum computing can and cannot go on problems with no structure.

The problem

Finding a specific item in an unsorted list or database without any shortcut like sorting.

History

Lov Grover, then at Bell Labs, published the algorithm at the ACM Symposium on Theory of Computing in 1996, two years after Shor's. It was a surprise because many researchers expected that quantum computers would help only with highly structured problems like factoring. Grover showed that even brute-force search benefits.

Boyer, Brassard, Høyer, and Tapp extended it in 1998 to the case where the number of solutions is unknown, and Brassard, Høyer, and Tapp created the related quantum counting algorithm. The method was later generalized by Brassard, Høyer, Mosca, and Tapp into amplitude amplification, which can speed up any classical heuristic that uses randomness. Small versions have been run on all major hardware types, and the first implementations on two and three qubits appeared in the late 1990s and early 2000s.

Intuition

Imagine the quantum state as an arrow in a two-dimensional plane. One axis represents the marked answer, and the perpendicular axis represents the average of all unmarked items. At the start, an equal superposition over all N items is an arrow almost perpendicular to the answer axis, tilted by a small angle theta, where the sine of theta is the square root of the fraction of marked items.

Each Grover iteration rotates the arrow toward the answer by an angle of 2 theta. The rotation is built from two reflections. First, the oracle flips the sign of the marked item's amplitude, which reflects the arrow about the unmarked axis. Second, the diffusion operator reflects the arrow about the starting equal superposition. Two reflections make a rotation, and after about pi over 4 times the square root of N iterations the arrow lies almost exactly on the answer.

This picture explains two important facts. The algorithm must stop at the right time: if you keep iterating, the arrow rotates past the answer and the success probability falls again. And the speedup is limited to quadratic because each rotation step is a fixed small angle, so the number of steps needed scales with the inverse of that angle.

How it works

Repeatedly applies an oracle that marks the correct answer, then amplifies its probability through reflection operations, concentrating probability onto the right answer.

  1. Prepare n qubits, where N = 2 to the n, and apply a Hadamard gate to each so that all N basis states have equal amplitude 1 over the square root of N.
  2. Apply the oracle, a quantum circuit that flips the sign of the amplitude of any state that satisfies the search condition and leaves the rest unchanged.
  3. Apply the diffusion operator: Hadamard on every qubit, a conditional phase flip on the all-zeros state, and Hadamard again. This reflects all amplitudes about their average and thereby amplifies the marked one.
  4. Repeat steps 2 and 3 about pi over 4 times the square root of N divided by M times, where M is the number of solutions.
  5. Measure all qubits. With probability close to 1, the result is a marked item.
  6. Verify the answer with one classical check, since the oracle can be evaluated classically on the candidate. If the check fails, repeat.

Worked example

Consider N = 4 items with one marked, which fits in two qubits. The starting state has amplitude one half on each item, and the angle theta satisfies sine of theta equal to one half, so theta is 30 degrees. One Grover iteration rotates the arrow by 60 degrees to 90 degrees, which points exactly at the marked item, so a single iteration finds it with probability 1. A classical computer would need up to three guesses.

With N = 1,000,000 and one marked item, a classical search takes about 500,000 checks on average, while Grover's algorithm needs about 785 iterations. At N = 2 to the 64, the numbers become 2 to the 63 versus about 2 to the 32 iterations, which is the basis of the claim that Grover's algorithm halves the effective key length of a symmetric cipher.

Complexity and resources

Queries (one solution)About (pi over 4) times the square root of N
Queries (M solutions)About (pi over 4) times the square root of N over M
Classical equivalentAbout N over 2 queries on average, N in the worst case
Lower boundOmega of the square root of N quantum queries, so Grover's algorithm is optimal
Qubitsn qubits for the search register plus ancillas that depend on the oracle

Hardware needs

A reliable implementation of the oracle, which is often the most expensive part and can require many ancilla qubits and deep circuits.

Coherence long enough to run hundreds to millions of iterations without error, so practical large searches need error correction.

For cryptographic key search, extremely large numbers of sequential iterations that cannot be easily parallelized.

Real-world impact

Broadly applicable to search and optimization problems; also halves the effective key strength of certain symmetric encryption schemes.

Applications

Searching databases or solution spaces when only a yes or no check is available, such as satisfiability, constraint solving, and puzzle solving.

Speeding up other algorithms through amplitude amplification, for example in quantum counting, minimum finding, and collision finding.

Estimating security margins for symmetric cryptography and hash functions, which is why AES-256 is recommended for long-term security.

Serving as a standard benchmark and teaching example on real quantum hardware.

Limitations

  • The speedup is only quadratic, so for many problems the overhead of error correction can cancel the gain on realistic hardware.
  • Building the oracle may cost more than the search itself, and loading classical data into the oracle is expensive.
  • It does not parallelize well: running k machines in parallel gives only a square root of k speedup, so it is worse than classical parallelism.
  • Overshooting the optimal number of iterations lowers the success probability.

Common misconceptions

  • It does not search a list instantly. It needs about the square root of N steps, which is still large.
  • It does not break AES. It effectively halves the key length in the idealized model, which AES-256 and similar ciphers are designed to tolerate.
  • It cannot search a real-world database by itself, because loading the data into a quantum state is the bottleneck.

How it compares

Shor's algorithm has an exponential advantage for a specific structured problem, while Grover's has a smaller but much broader advantage.

Amplitude amplification generalizes Grover's algorithm to speed up any process that succeeds with some probability.

Quantum walk search can match the square root scaling on structured graphs and sometimes beats Grover in specific settings.

Why it matters

Grover's algorithm shows the limits of quantum computing as much as its power. It proves that for problems without structure, a quantum computer can do no better than a quadratic improvement, which helps people reason about which problems are worth attacking.

It also underlies a great deal of later work. Amplitude amplification, counting, and minimum finding all use the same rotation idea, and many resource estimates for cryptanalysis rely on Grover's algorithm to set key sizes.

The problem Grover framed, in his own example

Lov Grover's 1996 paper is titled 'A fast quantum mechanical algorithm for database search' (arXiv quant-ph/9605043). It opens with a phone-directory example: N unsorted names, and you want the name that goes with a given number. A classical algorithm, whether deterministic or probabilistic, has to look at about N/2 entries to have a 50 percent chance of finding the answer. The quantum method the paper proposes uses superposition to examine many entries at once, with phase adjustments that reinforce the correct answer and cancel the others, and it needs only O(sqrt(N)) steps.

The paper also says this is within a small constant factor of the fastest possible quantum algorithm for the task. That statement is the reason Grover's algorithm is described as optimal: you cannot do much better than a square-root number of queries with any quantum method on a truly unstructured problem.

How amplitude amplification works, step by step

The algorithm starts with an equal superposition over all N possibilities, so every item has the same small amplitude. Each Grover iteration has two parts. First an oracle flips the sign of the amplitude of the marked item, which is invisible to a measurement on its own because probabilities depend on amplitude squared. Second a 'diffusion' step reflects all amplitudes about their average. Because the marked item is now below the average, that reflection pushes it up, and every other amplitude down slightly.

A good geometric picture is a rotation. The state lives in a plane spanned by 'the marked item' and 'everything else', and each iteration rotates the state by a fixed small angle towards the marked item. After roughly (pi/4) times sqrt(N) iterations the state points almost exactly at the answer. This also reveals the main trap: if you keep iterating, you rotate past the target and the success probability falls again. Grover's algorithm needs the number of iterations to be chosen correctly, which requires knowing how many items are marked, or using a counting step first.

  • Start: uniform superposition over N items.
  • Repeat about (pi/4) x sqrt(N) times: oracle phase flip, then reflection about the mean.
  • Measure: the marked item appears with high probability.
  • Too many iterations lowers the success probability again.

Quadratic, not exponential, and what that costs in practice

A quadratic speedup sounds large: searching a trillion items takes about a million iterations instead of a trillion lookups. In practice the comparison is harder. Each Grover iteration includes a full oracle call, and the oracle has to be built as a quantum circuit that can recognise a correct answer. On error-corrected hardware, the time per iteration is slow compared with a classical processor doing a memory lookup, so the crossover point where the quantum search is actually faster in wall-clock time can be very large. Whether a given problem benefits depends on how expensive the oracle is and how fast the quantum machine's cycles are.

The speedup also applies to unstructured search. If your data is sorted, indexed or hashed, classical algorithms already answer in logarithmic or constant time, and Grover's algorithm offers nothing. The realistic use cases are problems where the best known classical approach really is to try candidates, such as certain constraint-satisfaction problems or brute-force key search, and even there the oracle is the main engineering challenge.

Grover and cryptography

A common claim is that Grover's algorithm halves the effective key length of symmetric ciphers: searching a 128-bit key space classically takes about 2^128 trials, and quantum search takes about 2^64 iterations. That is a fair first approximation of the query count. It overlooks the cost of implementing the cipher inside the oracle and the fact that the iterations are sequential and hard to parallelise, so the practical advantage is smaller than the headline. The usual security advice is to prefer larger key sizes rather than to treat symmetric encryption as broken.

This is a good contrast with Shor's algorithm. Shor gives an exponential advantage on a structured problem and forces a change of public-key algorithms. Grover gives a quadratic advantage on an unstructured problem and mostly forces larger parameters.

Common misunderstandings

Grover's algorithm does not 'try all answers at once and pick the right one'. All amplitudes exist in superposition, but a measurement gives only one outcome, so without the interference steps you would find the marked item with probability 1/N. The algorithm is the interference, not the superposition. Nor does it search a database stored in a quantum memory for free: loading classical data into a form that can be queried in superposition is itself a costly step, discussed under QRAM elsewhere on this site.

Frequently asked questions

How much faster is Grover's algorithm?

Quadratically faster: it needs about the square root of N queries instead of about N. For one million items that is roughly 785 steps instead of 500,000.

Does Grover's algorithm break encryption?

It weakens symmetric keys, effectively halving their bit length in theory, so a 128-bit key offers about 64 bits of security against an ideal quantum attacker. Using 256-bit keys restores a comfortable margin.

What is an oracle in Grover's algorithm?

An oracle is a circuit that recognizes a correct answer and flips its sign. It stands in for the problem-specific checking function.

Why does Grover's algorithm stop at a particular number of steps?

Each iteration rotates the state toward the answer by a fixed angle. If you continue past the optimal number of rotations, the state moves past the answer and the success probability drops.

Is Grover's algorithm useful on current hardware?

Only for tiny examples. A useful speedup needs fault-tolerant machines because the oracle and the iterations are deep.

Related algorithms

References and further reading

Sources opened and checked on December 1, 2026. Resource estimates and claims change, so check the originals.

  1. A fast quantum mechanical algorithm for database search (arXiv (L. K. Grover)) Opened. Source for the phone-directory example, the N/2 classical cost and the O(sqrt(N)) result.
  2. Quantum Algorithms Revisited (arXiv (Cleve, Ekert, Macchiavello, Mosca)) Opened. Background on interference as the common mechanism.

→ Read the full deep-dive in our Learning Center

← Back to Algorithms Database