← Quantum Information & Computing
πŸ”

Grover's Search Algorithm

Grover's algorithm searches an unsorted database of N items for a marked entry in O(√N) steps β€” a quadratic speedup over the classical O(N) requirement. While not exponential, this is provably optimal for quantum computers (Bennett et al. 1997) and translates to massive practical gains: searching one trillion items in a million steps instead of half a trillion.

Key Concepts

Unstructured Search
Given N items with no ordering or structure, find the unique marked item βˆ£Ο‰βŸ©|\omega\rangle. Classically, each query checks one item; expected O(N/2) queries. Quantum mechanics allows amplitude amplification to boost the probability of finding βˆ£Ο‰βŸ©|\omega\rangle to near certainty in O(√N) queries.
Grover Oracle
The oracle UΟ‰βˆ£x⟩=βˆ’βˆ£x⟩U_\omega|x\rangle = -|x\rangle if x=Ο‰x = \omega, else +∣x⟩+|x\rangle. It marks the target by flipping its phase β€” a phase oracle. Implemented as a black box that recognizes the answer without revealing it. Each application constitutes one 'query.'
Grover Diffusion Operator
The operator Us=2∣s⟩⟨sβˆ£βˆ’IU_s = 2|s\rangle\langle s| - I where ∣s⟩=HβŠ—n∣0n⟩|s\rangle = H^{\otimes n}|0^n\rangle is the uniform superposition. It reflects amplitudes about the mean, amplifying the marked state's amplitude and suppressing all others. Also called inversion-about-the-mean.
Amplitude Amplification
Alternating oracle UΟ‰U_\omega and diffusion UsU_s rotates the state toward βˆ£Ο‰βŸ©|\omega\rangle by angle 2ΞΈ2\theta per iteration where sin⁑θ=1/N\sin\theta = 1/\sqrt{N}. After kβ‰ˆΟ€4Nk \approx \frac{\pi}{4}\sqrt{N} iterations, the probability of measuring βˆ£Ο‰βŸ©|\omega\rangle approaches 1.
Optimality
Grover's algorithm is provably optimal: no quantum algorithm can search N items in fewer than Ξ©(N)\Omega(\sqrt{N}) queries (BBBV theorem, 1997). The quadratic speedup cannot be improved β€” there is no quantum algorithm that searches in O(N^{1/3}) or better.
Multiple Solutions
If there are MM marked items among NN, the optimal number of Grover iterations is Ο€4N/M\frac{\pi}{4}\sqrt{N/M}. With M=N/4M = N/4, only 1 iteration suffices. The BBHT algorithm handles unknown MM with a quantum exponential search that finds a solution in O(N/M)O(\sqrt{N/M}) queries.

Key Equations

Grover Iteration Count
kβˆ—=βŒŠΟ€4NβŒ‹k^* = \left\lfloor \frac{\pi}{4}\sqrt{N} \right\rfloor
Optimal number of Grover iterations for N items (1 marked solution).
Success Probability
Psuccess(k)=sin⁑2 ⁣((2k+1)arcsin⁑1N)P_{\text{success}}(k) = \sin^2\!\left((2k+1)\arcsin\frac{1}{\sqrt{N}}\right)
Probability of measuring the marked item after k Grover iterations.
Classical vs Quantum Queries
Qclassical=O(N),Qquantum=O(N)Q_{\text{classical}} = O(N), \quad Q_{\text{quantum}} = O(\sqrt{N})
Quantum gives a quadratic speedup β€” square root instead of linear in N.
Grover Operator
G=Usβ‹…UΟ‰=(2∣s⟩⟨sβˆ£βˆ’I)(Iβˆ’2βˆ£Ο‰βŸ©βŸ¨Ο‰βˆ£)G = U_s \cdot U_\omega = (2|s\rangle\langle s|-I)(I - 2|\omega\rangle\langle\omega|)
One Grover iteration: oracle then diffusion about mean.
Worked Example

Grover's Search for N=4

Problem

For N=4N=4 items (2-qubit register), find the optimal number of Grover iterations and the success probability.

Solution

Compute optimal iterations:

kβˆ—=βŒŠΟ€44βŒ‹=βŒŠΟ€4β‹…2βŒ‹=βŒŠΟ€2βŒ‹=⌊1.571βŒ‹=1k^* = \left\lfloor\frac{\pi}{4}\sqrt{4}\right\rfloor = \left\lfloor\frac{\pi}{4}\cdot 2\right\rfloor = \left\lfloor\frac{\pi}{2}\right\rfloor = \lfloor 1.571 \rfloor = 1

After 1 iteration, success probability:

P=sin⁑2 ⁣(3arcsin⁑12)=sin⁑2 ⁣(3β‹…Ο€6)=sin⁑2 ⁣(Ο€2)=1P = \sin^2\!\left(3\arcsin\frac{1}{2}\right) = \sin^2\!\left(3 \cdot \frac{\pi}{6}\right) = \sin^2\!\left(\frac{\pi}{2}\right) = 1
Answer 1 iteration gives P(success) = 100% for N=4.
Practice

Exercises

5 problems
1 of 5

For N=4N=4 items, the optimal Grover iterations =βŒŠΟ€N/4βŒ‹= \lfloor \pi\sqrt{N}/4 \rfloor. How many?

iterations
2 of 5

For N=16N=16, optimal iterations =βŒŠΟ€16/4βŒ‹=βŒŠΟ€βŒ‹= \lfloor \pi\sqrt{16}/4 \rfloor = \lfloor \pi \rfloor. How many?

iterations
3 of 5

Classical random search of N=1000N=1000 items: expected number of queries = N/2N/2. How many?

Unlock Exercise 3

Subscribe to PhysWeb Pro to access all exercises and track your progress.

Upgrade to Pro β†’
4 of 5

Grover's algorithm searches N=1000N=1000 items in O(N)O(\sqrt{N}) queries. 1000β‰ˆ\sqrt{1000} \approx?

Unlock Exercise 4

Subscribe to PhysWeb Pro to access all exercises and track your progress.

Upgrade to Pro β†’
5 of 5

The quantum/classical speedup ratio for N=10000N=10000: classical needs N/2=5000N/2=5000, quantum needs N=100\sqrt{N}=100. Ratio classical/quantum?

Unlock Exercise 5

Subscribe to PhysWeb Pro to access all exercises and track your progress.

Upgrade to Pro β†’

Key Takeaways

  • Grover finds a marked item in O(N)O(\sqrt{N}) queries β€” a quadratic speedup over classical O(N)O(N).
  • Each iteration applies the oracle (phase flip on target) then diffusion (inversion about the mean).
  • Optimal iterations: kβˆ—=βŒŠΟ€4NβŒ‹k^* = \lfloor \frac{\pi}{4}\sqrt{N} \rfloor; over-iterating reduces success probability.
  • The quadratic speedup is provably optimal β€” no quantum algorithm can do better than O(N)O(\sqrt{N}).
  • With MM solutions among NN items, optimal iterations become Ο€4N/M\frac{\pi}{4}\sqrt{N/M}.