Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

QCQI – Chapter 8 Detailed Summary: Grover Search & Amplitude Amplification

Learning Objectives

  • Implement the Grover iterate G=D OfG = D\,O_f where OfO_f marks “good” states and DD is diffusion.

  • Explain the two-dimensional geometry (good/bad subspace), derive the optimal iteration count, and quantify success.

  • Generalize to amplitude amplification with arbitrary state-preparation AA and reflection operators.

  • Understand amplitude estimation / quantum counting at a high level.

  • Build small oracles and diffusion circuits and explore multiple-solution cases.

Problem Statement & Oracle

Unstructured search: given f:{0,…,N−1}→{0,1}f:\{0,\dots,N-1\}\to\{0,1\} with M=∣f−1(1)∣M=\left|f^{-1}(1)\right|, find any xx with f(x)=1f(x)=1.

Oracle OfO_f acts as a phase flip on marked basis states: Of∣x⟩=(−1)f(x)∣x⟩. O_f|x\rangle = (-1)^{f(x)}|x\rangle.

Eureka! Phase oracles are lossless: a global phase on marked states becomes actionable after interference via the diffuser.

State Decomposition & Geometry

Let SS (good) have size MM; define ∣α⟩=1N−M∑x∉S∣x⟩|\alpha\rangle=\frac{1}{\sqrt{N-M}}\sum_{x\notin S}|x\rangle and ∣β⟩=1M∑x∈S∣x⟩|\beta\rangle=\frac{1}{\sqrt{M}}\sum_{x\in S}|x\rangle. Initialize ∣s⟩=1N∑x∣x⟩=sin⁡θ ∣β⟩+cos⁡θ ∣α⟩|s\rangle=\frac{1}{\sqrt{N}}\sum_x |x\rangle=\sin\theta\,|\beta\rangle+\cos\theta\,|\alpha\rangle with sin⁡θ=M/N\sin\theta=\sqrt{M/N}.

Eureka! Grover is a planar rotation in span{∣α⟩,∣β⟩}\{|\alpha\rangle,|\beta\rangle\} by angle 2θ2\theta each iterate.

Grover Iterate

Oracle OfO_f reflects across ∣α⟩|\alpha\rangle (phase flip on ∣β⟩|\beta\rangle). Diffusion D=2∣s⟩ ⁣⟨s∣−ID=2|s\rangle\!\langle s|-I reflects across ∣s⟩|s\rangle. Therefore G=DOf G=DO_f is a rotation by 2θ2\theta. After rr iterations, Gr∣s⟩=sin⁡((2r+1)θ)∣β⟩+cos⁡((2r+1)θ)∣α⟩. G^r|s\rangle=\sin((2r+1)\theta)|\beta\rangle+\cos((2r+1)\theta)|\alpha\rangle.

Optimal count. Choose r⋆=⌊π4θ−12⌋≈⌊π4NM⌋r^\star=\left\lfloor \frac{\pi}{4\theta}-\frac12\right\rfloor \approx \left\lfloor \frac{\pi}{4}\sqrt{\frac{N}{M}} \right\rfloor. Success ≈sin⁡2((2r⋆+1)θ)≳1−O(M/N)\approx \sin^2((2r^\star+1)\theta)\gtrsim 1- O(M/N).

Eureka! Quadratic speedup: Θ(N/M)\Theta(\sqrt{N/M}) queries vs. classical Θ(N/M)\Theta(N/M).

Diffusion Operator Circuits

Using ∣s⟩=H⊗n∣0n⟩|s\rangle=H^{\otimes n}|0^n\rangle, D=H⊗n (2∣0⟩ ⁣⟨0∣−I) H⊗n. D = H^{\otimes n}\,(2|0\rangle\!\langle 0|-I)\,H^{\otimes n}. Implement 2∣0⟩ ⁣⟨0∣−I2|0\rangle\!\langle 0|-I by an nn-controlled-ZZ (phase flip on ∣0n⟩|0^n\rangle), e.g., for n=3n=3: HH–CCX–HH on the last qubit with appropriate XX conjugations to retarget.

Eureka! “Reflect about ∣s⟩|s\rangle”   ⟺  \iff reflect about ∣0n⟩|0^n\rangle in the Hadamard basis.

Multiple Solutions & Overshoot

With M>1M>1, θ\theta increases; over-iterating rotates past the target. Use the same r⋆r^\star formula with MM known or guessed (or use fixed-point search variants to avoid overshoot).

Amplitude Amplification (General Form)

Given A∣0⟩=sin⁡θ ∣β⟩+cos⁡θ ∣α⟩A|0\rangle = \sin\theta\,|\beta\rangle+\cos\theta\,|\alpha\rangle (any preparation), define reflections S0=I−2∣0⟩ ⁣⟨0∣,Sf=I−2Πgood.S_0 = I - 2|0\rangle\!\langle 0|,\qquad S_f=I-2\Pi_{\text{good}}. Then the iterate Q=−AS0A†Sf Q = -A S_0 A^\dagger S_f rotates by 2θ2\theta in the same two-dimensional subspace.

Eureka! Grover is just A=H⊗nA=H^{\otimes n} with the good-subspace projector defined by ff.

Amplitude Estimation & Counting (Idea)

Combine QPE with the Grover iterate QQ to estimate θ\theta (or MM) without scanning rr: phase of QQ’s eigenvectors is ±2θ\pm 2\theta. Quantum counting estimates M≈Nsin⁡2θM\approx N\sin^2\theta.

Worked Nuggets

Mark a single item. Conjugate an nn-controlled-ZZ with XX on bits where the target has 0.

Diffuser for n=3n=3. H⊗3 X⊗3 CCZ X⊗3 H⊗3H^{\otimes 3}\, X^{\otimes 3}\, \mathrm{CCZ}\, X^{\otimes 3}\, H^{\otimes 3}.

General success curve. Pr=sin⁡2((2r+1)θ)P_r=\sin^2((2r+1)\theta); the first maximum is near r⋆r^\star.

Pseudo-code Aids

Pseudocode — Grover (one marked string, nn small)

Input: nn, marked bitstring mm, iterations rr Prepare ∣s⟩=H⊗n∣0n⟩|s\rangle=H^{\otimes n}|0^n\rangle Repeat rr times: Oracle: for each bit jj with mj=0m_j=0 apply XX on jj; apply nn-controlled-ZZ; undo the XX’s Diffuser: apply H⊗nH^{\otimes n}; X⊗nX^{\otimes n}; nn-controlled-ZZ; X⊗nX^{\otimes n}; H⊗nH^{\otimes n} Measure in computational basis

Pseudocode — Optimal iteration estimate

Input: N=2nN=2^n, guess MM θ=arcsin⁡M/N\theta=\arcsin\sqrt{M/N}; r⋆=⌊π4θ−12⌋r^\star=\left\lfloor \frac{\pi}{4\theta}-\frac12\right\rfloor

Pseudocode — Amplitude amplification (general)

Input: state-prep AA, projector Πgood\Pi_{\text{good}} Set S0=I−2∣0⟩ ⁣⟨0∣S_0=I-2|0\rangle\!\langle 0|, Sf=I−2ΠgoodS_f=I-2\Pi_{\text{good}} Iterate Q=−AS0A†SfQ=-A S_0 A^\dagger S_f for rr steps; measure

Schematics

Grover Iterate G=D OfG = D\,O_f (concept)

2D Rotation Picture

Hands-on Notebook (Multi-Backend)

Run: L10_QCQI_Ch08_Grover_and_Amplitude_Amplification

In the first cell set backend to one of: cirq, pennylane, braket, pyquil, or qiskit.

Mini-Lab Ideas

  1. For n=3n=3, mark one string and plot success vs. iterations to observe the sine-squared curve.

  2. Mark M=2M=2 strings; compare measured PrP_r with theory using θ=arcsin⁡M/N\theta=\arcsin\sqrt{M/N}.

  3. Replace H⊗nH^{\otimes n} by a biased AA (e.g., rotate first qubit) and verify amplitude amplification still performs planar rotations.