Grover’s algorithm, developed by Lov Grover in 1996, is another major quantum algorithm. It provides a powerful way for quantum computers to search through unsorted data much faster than any classical computer.
Grover’s algorithm can find the correct item in only about \( \sqrt{N} \) steps. That means if you had 1,000,000 items, a classical search might take around 500,000 steps, but a quantum computer using Grover’s algorithm would need only about 1,000 steps!
$$ \text{Number of steps} \ \approx \ \frac{\pi}{4} \sqrt{N} $$
In simpler terms, Grover’s algorithm gives a quadratic speed-up: it’s not exponentially faster like Shor’s algorithm, but still dramatically better than classical search for large datasets.
Grover’s Algorithm provides a way for quantum computers to search through unsorted data much faster than classical computers. Let’s explore it with a simple example using 4 items (2 qubits → \( N = 2^2 = 4 \)).
| Index (x) | Item | Is it the correct one? \( f(x) \) |
|---|---|---|
| 00 | Apple | 0 |
| 01 | Banana | 0 |
| 10 | Cherry | 0 |
| 11 | Mango | 1 ✅ |
Start with 2 qubits in \( |00⟩ \). Apply Hadamard gates to each qubit to get:
\( |ψ⟩ = \frac{1}{2} (|00⟩ + |01⟩ + |10⟩ + |11⟩) \)
This means the system now represents all four possible items simultaneously through superposition.
The oracle knows which item is correct and flips its phase (multiplies its amplitude by −1). After applying the oracle, the state becomes:
\( \frac{1}{2} (|00⟩ + |01⟩ + |10⟩ - |11⟩) \)
This marks the correct answer (|11⟩) without revealing it directly.
The Grover Diffusion Operator (or "inversion about the mean") boosts the amplitude of the marked item using interference.
Before amplification: each state has amplitude ≈ 0.5. After amplification:
\( |ψ⟩ = (0.25, 0.25, 0.25, 0.75) \)
The correct item |11⟩ now has the highest probability of being measured.
When the system is measured, it collapses into one of the basis states. Because |11⟩ has the highest amplitude, the result will almost certainly be:
\( |11⟩ \Rightarrow \text{Mango} \)
Classically, finding the correct item in a list of N items takes ~\( N/2 \) checks on average. Grover’s algorithm does it in about:
\( \frac{\pi}{4} \sqrt{N} \)
For \( N = 4 \), only one iteration is needed! For large databases, this provides a quadratic speed-up.