Education / Quantum Computing

Quantum Computing · Chapter 09

Quantum Search and Amplitude Amplification

In Chapter 7, Deutsch's algorithm used phase kickback and interference to determine a global property of a one-bit function in a single query. Many computational problems, however, ask us to find a specific input \(x\) among \(N = 2^n\) candidates that satisfies a condition \(f(x) = 1\).

We first study this search problem on four items and see how phase marking and reflection concentrate amplitude on the solution. We then analyze the geometry of the search for any \(N\) and extend the method to general initial states.

How can a quantum computation concentrate probability on a solution that it can recognize but does not yet know?

Suppose we are given a black-box test \(f(x)\) that outputs \(1\) for a single marked item among \(N\) candidates and \(0\) for all the others. Classically, finding the marked item in the worst case requires testing candidates one by one.

In Chapter 7, we saw how a phase oracle flips the sign of the amplitude on any input \(x\) with \(f(x) = 1\). By itself, however, changing the sign of an amplitude from \(+1/\sqrt{N}\) to \(-1/\sqrt{N}\) leaves its measurement probability unchanged at \(1/N\). How can subsequent operations turn that sign change into a high probability of observing the marked item?

In this chapter · 4 sections · 12 topics
  1. 9.1 Four-Item Search
    Topics in this section
    1. 9.1.1 Search predicates and classical queries
    2. 9.1.2 State preparation and phase marking
    3. 9.1.3 Reflection and final amplitudes
  2. 9.2 Search Geometry
    Topics in this section
    1. 9.2.1 Good and bad subspaces
    2. 9.2.2 Initial success amplitude
    3. 9.2.3 Reflections and rotations
  3. 9.3 Grover Iteration
    Topics in this section
    1. 9.3.1 Amplitude evolution
    2. 9.3.2 Iteration count and overshooting
    3. 9.3.3 Unknown marked fraction and verification
  4. 9.4 General Amplitude Amplification
    Topics in this section
    1. 9.4.1 Arbitrary state preparation
    2. 9.4.2 Reflection using preparation and its inverse
    3. 9.4.3 Success probability and resource cost
Reading guide · preparation, aims, and assumptions

Turn a phase mark into increased success probability and determine when to stop iterating.

Before you begin

Use phase oracles, reflections, and normalized state vectors.

What you should be able to do

The example to follow

Start with four equal amplitudes; carry the same reflection picture into the good/bad two-dimensional plane.

Scope and assumptions

The standard iteration formula assumes ideal reflections and a fixed marked subspace. The best iteration count depends on the initial success probability.

9.1

Four-Item Search

Before analyzing search over an arbitrary number of candidates \(N = 2^n\), let us trace a complete quantum search over \(N = 4\) two-bit candidates with a single marked item—small enough that we can follow all four amplitudes by hand. Two operations drive the search: a phase oracle that flips the sign of the marked item's amplitude, and a reflection about the mean that converts that sign flip into certainty.

9.1.1 Search predicates and classical queries§

markedpredicate

Many computational problems can be phrased as searching a domain of \(N = 2^n\) candidate bit strings for an item \(x\in\{0,1\}^n\) that passes a verification test. We model that test as a Boolean predicate \(f:\{0,1\}^n\to\{0,1\}\), where \(f(x)=1\) means candidate \(x\) is marked (a valid solution) and \(f(x)=0\) means \(x\) is unmarked.

Suppose we are promised that exactly one of the \(N\) candidates is marked, and our only way to learn about \(f\) is by querying the black box on chosen inputs. How many queries does a classical algorithm need? In the worst case, a deterministic classical search must query \(N-1\) distinct candidates (if all \(N-1\) return \(0\), the remaining untested candidate must be the marked one). What if we use a randomized classical algorithm that is allowed to fail with probability \(1/3\)? If the marked item is hidden uniformly at random among the \(N\) candidates, each classical query tests only a single candidate, so after \(q\) distinct queries the marked item has been found with probability \(q/N\) (plus at most \(1/N\) if the algorithm guesses one remaining item at the end). Reaching success probability \(2/3\) therefore still requires roughly \(2N/3\) queries! Whether deterministic or randomized, classical unstructured search requires a number of queries proportional to \(N\).

Let us start with \(N = 4\) two-bit candidates—\(00, 01, 10, 11\)—and suppose the hidden marked item is \(w = 11\). Keep in mind that our choice of \(11\) is solely so we can write down a concrete numerical example: the search algorithm itself does not know which string is marked and accesses \(f\) exclusively through the oracle.

Test a candidate labelA computational-basis input and a blank target implement one predicate test. M reads whether x is marked; this is classical value-query behaviour represented with the reversible oracle. Read each circuit left to right.Test a candidate label|x⟩|0⟩f(x)U_fM
A computational-basis input and a blank target implement one predicate test. M reads whether x is marked; this is classical value-query behaviour represented with the reversible oracle.
Problems
  1. A predicate on three-bit labels marks the labels whose bits add to \(2\). How many labels are marked, and what is the probability that a uniformly random label is marked?

    Show solutionHide solution

    The marked labels are \(011\), \(101\), and \(110\): three of the eight. A random label is marked with probability \(3/8\).

  2. One label among \(N=8\) is marked. A classical search queries labels in a uniformly random order, without repetition, until it finds the marked one. What is the expected number of queries?

    Show solutionHide solution

    The marked label is equally likely to be in any of the \(8\) positions of the order, so the expected number of queries is \((1+2+\dots+8)/8=(N+1)/2=4.5\).

  3. One label among \(N\) is marked, in a uniformly random position. Show that any classical algorithm making \(k\) queries finds it with probability at most \(k/N\).

    Show solutionHide solution

    Consider first a deterministic algorithm. Until it finds the label, every answer is \(0\), so its sequence of queries before success is fixed in advance: some \(k\) labels. It succeeds exactly when the marked label is among them, with probability at most \(k/N\). A randomized algorithm is an average of deterministic ones, so it too succeeds with probability at most \(k/N\). Constant success therefore needs a number of queries proportional to \(N\).

9.1.2 State preparation and phase marking§

uniform superposition

How does a quantum search begin? Since we have no advance clue about which of the four candidates \(00, 01, 10, 11\) is marked, we initialize two qubits in \(\ket{00}\) and apply \(H\otimes H\) to prepare the uniform superposition of all four candidates:

\[\ket{s} = (H\otimes H)\ket{00} = \frac{\ket{00}+\ket{01}+\ket{10}+\ket{11}}{2}.\]

Next, we query the predicate \(f\) using the phase-oracle construction from Chapter 7 (either by kicking back a phase from an ancilla in \(\ket{-}\) or by the compute, phase, uncompute sequence \(A^\dagger Z_{\mathrm{ans}} A\)), which applies the phase-marking operator

\[O_f\ket{x} = (-1)^{f(x)}\ket{x}.\]

When \(w = 11\) is the marked string (\(f(11)=1\) and \(f(00)=f(01)=f(10)=0\)), one call to \(O_f\) negates the amplitude of \(\ket{11}\) while leaving the other three amplitudes at \(+1/2\):

\[O_f\ket{s} = \frac{\ket{00}+\ket{01}+\ket{10}-\ket{11}}{2}.\]

Has this phase flip increased our chance of observing \(11\) if we measure right now? Not yet: the squared magnitude of every coordinate—both \((+1/2)^2\) and \((-1/2)^2\)—is still \(1/4\)! Just as in Deutsch's algorithm, the oracle has encoded the location of the marked item into a relative minus sign; we now need an interference step that converts that minus sign into an amplitude difference.

Prepare and mark four candidatesTwo H gates prepare the uniform state. Controlled-Z marks 11 by changing only its sign; it does not change immediate measurement probabilities. Read each circuit left to right.Prepare and mark four candidates|0⟩|0⟩HHOutput amplitudes in order 00, 01, 10, 11: (1,1,1,−1)/2
Two H gates prepare the uniform state. Controlled-Z marks 11 by changing only its sign; it does not change immediate measurement probabilities.
Problems
  1. For \(N=4\) with the label \(01\) marked, write the amplitudes after preparing the uniform superposition and applying the phase oracle.

    Show solutionHide solution

    \(\tfrac12(1,-1,1,1)\), in the order \(00,01,10,11\).

  2. For \(N=8\) with one marked label, what are the amplitudes after preparation and marking, and what is the probability of measuring the marked label?

    Show solutionHide solution

    Every amplitude is \(1/\sqrt8\), except the marked one, which is \(-1/\sqrt8\). The marked label is measured with probability \(1/8\), the same as before marking.

  3. Show that applying the phase oracle any number of times, with nothing in between, never changes any measurement probability.

    Show solutionHide solution

    \(O_f\) multiplies each amplitude by \(\pm1\), so it leaves every magnitude unchanged. Moreover \(O_f^2=I\), so any number of applications equals \(I\) or \(O_f\). The probabilities never change; an operation that mixes amplitudes is needed.

9.1.3 Reflection and final amplitudes§

reflection about the mean

What unitary operation can turn the amplitude vector \((1/2, 1/2, 1/2, -1/2)^T\) into a vector concentrated on the marked coordinate? Look at the average (mean) of the four amplitudes after \(O_f\):

\[\mu = \frac{\frac{1}{2} + \frac{1}{2} + \frac{1}{2} - \frac{1}{2}}{4} = \frac{1}{4}.\]

Notice that the three unmarked amplitudes (\(+1/2\)) sit slightly above the mean \(\mu = 1/4\) (by \(+1/4\)), whereas the marked amplitude (\(-1/2\)) sits far below the mean \(\mu = 1/4\) (by \(-3/4\)). What happens if we reflect every coordinate across the mean \(\mu\), replacing each amplitude \(a_x\) with \(2\mu - a_x\)?

\[\text{Unmarked }\bigl(a_x = +\tfrac{1}{2}\bigr):\quad 2\left(\frac{1}{4}\right) - \frac{1}{2} = 0,\qquad\qquad \text{Marked }\bigl(a_{11} = -\tfrac{1}{2}\bigr):\quad 2\left(\frac{1}{4}\right) - \left(-\frac{1}{2}\right) = 1.\]

Every unmarked amplitude drops to \(0\), and the marked amplitude jumps to \(1\)! After just one phase-oracle call and one reflection about the mean, the register is in the state \(\ket{11}\), and a computational-basis measurement finds the marked item \(11\) with probability \(1\).

Why is "reflection about the mean" a valid unitary operation that can be applied without knowing which item is marked? Let us check that it is identical to the diffusion operator \(D\) we built from Hadamard and controlled-\(Z\) gates in Section 8.2.3:

\[D = 2\ketbra{s}{s} - I.\]

For any state \(\ket{a} = \sum_x a_x\ket{x}\) in an \(N\)-item search space where \(\ket{s} = \frac{1}{\sqrt{N}}\sum_x \ket{x}\), the inner product \(\braket{s}{a} = \frac{1}{\sqrt{N}}\sum_x a_x = \sqrt{N}\,\mu\), where \(\mu = \frac{1}{N}\sum_x a_x\) is the arithmetic mean of the amplitudes. Multiplying by \(2\ket{s}\) puts \(\frac{2}{\sqrt{N}}(\sqrt{N}\mu) = 2\mu\) into every coordinate, so subtracting \(\ket{a}\) gives \(D\ket{a} = \sum_x (2\mu - a_x)\ket{x}\)! Because \(D = H^{\otimes n}(2\ketbra{0^n}{0^n}-I)H^{\otimes n}\) is a product of unitary matrices (with \(D^\dagger = D\) and \(D^2 = I\)), it acts directly on the amplitudes by coherent interference—without ever sampling or estimating \(\mu\) classically.

Four-item search circuitPrepare two plus states, mark eleven using controlled Z, then apply H X controlled Z X H on both wires. The reflection differs from diffusion only by global phase.|0⟩H|0⟩HHHXXXXHHmark 11reflection (up to global phase)
Complete two-qubit Grover search for \(w=11\): initial Hadamards prepare \(\ket{s}\), the first controlled-\(Z\) acts as \(O_f\) to mark \(\ket{11}\), and the diffusion circuit implements \(-D\) (reflection about the mean up to a global minus sign), yielding outcome \(11\) with certainty.
Problems
  1. Reflect the amplitudes \(\tfrac12(1,-1,1,1)\) about their mean.

    Show solutionHide solution

    The mean is \(\tfrac14\). The entries \(\tfrac12\) become \(2\cdot\tfrac14-\tfrac12=0\), and \(-\tfrac12\) becomes \(\tfrac12+\tfrac12=1\). The result is \((0,1,0,0)\): the marked label \(01\) with certainty.

  2. For \(N=8\) with one marked label, compute the amplitudes after one marking and one reflection about the mean, and the success probability.

    Show solutionHide solution

    Write \(a=1/\sqrt8\). After marking, seven amplitudes are \(a\) and one is \(-a\), so the mean is \(6a/8=3a/4\). The unmarked amplitudes become \(3a/2-a=a/2\), and the marked one becomes \(3a/2+a=5a/2\). The success probability is \((5a/2)^2=25/32\approx0.78\), up from \(1/8\). The seven unmarked probabilities, \(1/32\) each, account for the remaining \(7/32\).

  3. Show directly from \(a_x\mapsto2\mu-a_x\) that reflection about the mean preserves the sum of squared amplitudes, for real amplitudes.

    Show solutionHide solution

    \(\sum_x(2\mu-a_x)^2=\sum_x\bigl(4\mu^2-4\mu a_x+a_x^2\bigr)=4N\mu^2-4\mu\cdot N\mu+\sum_xa_x^2=\sum_xa_x^2\), using \(\sum_xa_x=N\mu\).

9.2

Search Geometry

For four candidates, we could track every coordinate by hand. What happens when we search millions or billions of candidates (\(N = 2^n\)), with \(M\) of them marked? Remarkably, we never need to track \(N\) separate numbers: because the initial state \(\ket{s}\), the oracle \(O_f\), and the reflection \(D\) treat all marked items identically and all unmarked items identically, the entire \(N\)-dimensional evolution stays confined to a two-dimensional plane that we can draw on the page.

9.2.1 Good and bad subspaces§

good and bad subspaces

Suppose that among the \(N = 2^n\) basis strings, there are \(M\) marked strings (with \(0 \lt M \lt N\)) satisfying \(f(x)=1\), and \(N-M\) unmarked strings satisfying \(f(x)=0\). Because our starting state \(\ket{s}\) assigns equal amplitude to every string, and both \(O_f\) and \(D\) depend only on whether \(f(x)=1\) or \(f(x)=0\), all \(M\) marked strings will share a common amplitude at every step of the algorithm, and all \(N-M\) unmarked strings will share another common amplitude.

We can therefore bundle the \(M\) marked basis states into a single normalized unit vector \(\ket{G}\) (for "good") and the \(N-M\) unmarked basis states into a single normalized unit vector \(\ket{B}\) (for "bad"):

\[\ket{G} = \frac{1}{\sqrt{M}}\sum_{x:\,f(x)=1}\ket{x},\qquad \ket{B} = \frac{1}{\sqrt{N-M}}\sum_{x:\,f(x)=0}\ket{x}.\]

Because no basis string \(x\) is both marked and unmarked, \(\ket{G}\) and \(\ket{B}\) share no basis terms in common, so their inner product is zero: \(\braket{G}{B} = 0\). Together, the marked and unmarked states span the good and bad subspaces, and the two orthonormal vectors \(\{\ket{B}, \ket{G}\}\) define a two-dimensional plane inside the \(N\)-dimensional state space. In terms of \(\ket{G}\) and \(\ket{B}\), the uniform superposition \(\ket{s} = \frac{1}{\sqrt{N}}\sum_x \ket{x}\) decomposes as

\[\ket{s} = \sqrt{\frac{M}{N}}\,\ket{G} + \sqrt{\frac{N-M}{N}}\,\ket{B} = \sqrt{\frac{M}{N}}\,\ket{G} + \sqrt{1 - \frac{M}{N}}\,\ket{B}.\]

Notice why the coefficients are square roots: \(\ket{G}\) already includes the normalization factor \(1/\sqrt{M}\), so multiplying \(\ket{G}\) by \(\sqrt{M/N}\) gives each marked basis state its proper amplitude \(\frac{1}{\sqrt{M}}\sqrt{\frac{M}{N}} = \frac{1}{\sqrt{N}}\), and the squared magnitudes of the two components sum to \(\frac{M}{N} + \bigl(1 - \frac{M}{N}\bigr) = 1\).

Keep in mind that \(\ket{G}\) and \(\ket{B}\) are bookkeeping vectors for our mathematical analysis: the quantum computer does not know which strings belong to \(\ket{G}\), yet \(O_f\) and \(D\) automatically act within the plane spanned by \(\ket{B}\) and \(\ket{G}\) without needing that knowledge.

Group outcomes of the search circuitThe bundled wire carries the n-qubit search register. Good and bad components group its basis labels; they are not separate physical qubits. Read each circuit left to right.Group outcomes of the search circuit|0ⁿ⟩xH^(⊗ n)(DO_f)ᵏM|ψₖ⟩=aₖ|G⟩+bₖ|B⟩p(marked)=|aₖ|²
The bundled wire carries the n-qubit search register. Good and bad components group its basis labels; they are not separate physical qubits.
Problems
  1. For \(N=8\) with the marked labels \(011\) and \(101\), write \(\ket G\) and \(\ket B\).

    Show solutionHide solution

    \(\ket G=(\ket{011}+\ket{101})/\sqrt2\), and \(\ket B\) is the equal superposition of the other six labels, each with amplitude \(1/\sqrt6\).

  2. For \(N=8\) and \(M=2\), write \(\ket s\) as a combination of \(\ket G\) and \(\ket B\).

    Show solutionHide solution

    \(\ket s=\sqrt{2/8}\,\ket G+\sqrt{6/8}\,\ket B=\tfrac12\ket G+\tfrac{\sqrt3}2\ket B\).

  3. Show that the oracle \(O_f\) and the reflection \(D=2\ket s\bra s-I\) both map the plane of \(\ket G\) and \(\ket B\) into itself, by computing their action on \(\ket G\) and \(\ket B\).

    Show solutionHide solution

    \(O_f\ket G=-\ket G\) and \(O_f\ket B=\ket B\). With \(\ket s=\sin\theta\ket G+\cos\theta\ket B\), we have \(\braket sG=\sin\theta\) and \(\braket sB=\cos\theta\), so \(D\ket G=2\sin\theta\ket s-\ket G\) and \(D\ket B=2\cos\theta\ket s-\ket B\). Both are combinations of \(\ket G\) and \(\ket B\), so the state never leaves their plane.

9.2.2 Initial success amplitude§

success probability

Let us draw the two-dimensional plane with the unmarked state \(\ket{B}\) along the horizontal axis and the marked state \(\ket{G}\) along the vertical axis. Because \(0 \lt M \lt N\), we can define an acute angle \(\theta \in (0, \pi/2)\) by setting \(\sin\theta = \sqrt{M/N}\), so that

\[\sin^2\theta = \frac{M}{N},\qquad \cos\theta = \sqrt{1 - \frac{M}{N}}.\]

In this geometric picture, the initial uniform state \(\ket{s}\) is a unit vector tilted at angle \(\theta\) above the horizontal axis \(\ket{B}\):

\[\ket{s} = \sin\theta\,\ket{G} + \cos\theta\,\ket{B}.\]

If we measure \(\ket{s}\) immediately in the computational basis, the probability of obtaining any marked string—the initial success probability—is the sum of squared amplitudes over the \(M\) marked strings, which is simply the squared vertical component \(\sin^2\theta = M/N\). For our four-item example (\(N=4, M=1\)), \(\sin\theta = \sqrt{1/4} = 1/2\), so \(\ket{s}\) starts at \(\theta = \pi/6 = 30^\circ\) above \(\ket{B}\), with initial success probability \(\sin^2(30^\circ) = 1/4\).

Why does the state vector never leave this two-dimensional \(\ket{B}\)–\(\ket{G}\) plane during the algorithm? First, the phase oracle \(O_f\) multiplies every marked string by \(-1\) and leaves every unmarked string unchanged, so \(O_f\ket{G} = -\ket{G}\) and \(O_f\ket{B} = \ket{B}\). Second, the diffusion operator \(D = 2\ketbra{s}{s} - I\) maps any vector \(\ket{v}\) in the plane to \(2\braket{s}{v}\ket{s} - \ket{v}\), which is a linear combination of \(\ket{s}\) and \(\ket{v}\)—and since \(\ket{s}\) itself lies in the \(\ket{B}\)–\(\ket{G}\) plane, \(D\ket{v}\) stays in the plane too!

Readout before amplificationMeasuring the uniform preparation succeeds with probability M/N. The angle in the text describes this circuit’s initial amplitudes, not a second register. Read each circuit left to right.Readout before amplification|0ⁿ⟩xH^(⊗ n)M|s⟩=sinθ|G⟩+cosθ|B⟩, sin²θ=M/N
Measuring the uniform preparation succeeds with probability M/N. The angle in the text describes this circuit’s initial amplitudes, not a second register.
Problems
  1. Find the angle \(\theta\) for \(N=16\) with \(M=1\), and for \(N=8\) with \(M=2\).

    Show solutionHide solution

    For \(N=16\), \(M=1\): \(\sin\theta=1/4\), so \(\theta\approx14.5^\circ\). For \(N=8\), \(M=2\): \(\sin\theta=1/2\), so \(\theta=30^\circ\).

  2. For \(N=8\) and \(M=2\), how many iterations give success with certainty?

    Show solutionHide solution

    \(\theta=30^\circ\), as for \(N=4\), \(M=1\). One iteration turns the state to \(3\theta=90^\circ\), the good direction, so one iteration succeeds with certainty.

  3. Show that, for \(0\lt M\lt N\), exactly one Grover iteration gives certain success precisely when \(M/N=1/4\).

    Show solutionHide solution

    After one iteration the success probability is \(\sin^2(3\theta)\), which equals \(1\) when \(3\theta=\pi/2+j\pi\). For \(0\lt\theta\lt\pi/2\) this gives \(\theta=\pi/6\) only, since the next solution, \(\theta=\pi/2\), would mean \(M=N\). And \(\sin^2(\pi/6)=1/4=M/N\).

9.2.3 Reflections and rotations§

Grover iteration

What do \(O_f\) and \(D\) do geometrically inside the \(\ket{B}\)–\(\ket{G}\) plane? Look at each operation in turn:

  • The phase oracle \(O_f = I - 2\ketbra{G}{G}\) preserves the horizontal axis \(\ket{B}\) and negates the vertical axis \(\ket{G}\): it is a reflection across the horizontal axis \(\ket{B}\).
  • The diffusion operator \(D = 2\ketbra{s}{s} - I\) preserves the vector \(\ket{s}\) (which lies at angle \(\theta\) above \(\ket{B}\)) and negates the direction perpendicular to \(\ket{s}\): it is a reflection across the line of \(\ket{s}\).

What is the combined effect of performing two reflections in a plane across axes separated by an angle \(\theta\)? Measure every vector's angle from the horizontal axis \(\ket{B}\). A reflection across a mirror line at angle \(\alpha\) sends any vector at angle \(\phi\) to angle \(2\alpha - \phi\). Therefore:

  1. Applying \(O_f\) (reflection across \(\ket{B}\), where \(\alpha = 0\)) sends a vector at angle \(\phi\) to angle \(-\phi\).
  2. Applying \(D\) (reflection across \(\ket{s}\), where \(\alpha = \theta\)) sends that vector from angle \(-\phi\) to angle \(2\theta - (-\phi) = \phi + 2\theta\).

Two reflections make a rotation! Each combined step \(G_{\mathrm{iter}} = D O_f\)—called one Grover iteration—rotates the state vector in the \(\ket{B}\)–\(\ket{G}\) plane by a fixed angle \(2\theta\) toward the vertical marked axis \(\ket{G}\).

For our four-item search (\(N=4, M=1\)), \(\theta = 30^\circ\). The state starts at \(\ket{s}\) (angle \(\phi_0 = 30^\circ\)); \(O_f\) reflects it across \(\ket{B}\) to \(-30^\circ\); and \(D\) reflects it across \(\ket{s}\) (\(30^\circ\)) to angle \(30^\circ + 2(30^\circ) = 90^\circ\)—pointing straight along \(\ket{G}\), where success is \(100\%\) certain! Even more importantly, this geometric picture warns us what happens if we keep iterating past \(90^\circ\): the next Grover iteration will rotate the vector by another \(2\theta = 60^\circ\) to \(150^\circ\), carrying it away from \(\ket{G}\).

Interactive figure. This two-dimensional plane traces Grover’s iteration as a reflection \(O_f\) across the unmarked axis followed by a reflection \(D\) across the initial superposition \(\ket{s}\). Step through \(O_f\) and \(D\) for \(N=4\) to follow the state angle across two iterations.

Two reflections make a rotation

One pair of reflectionsOn a bundled register the oracle acts first and D second. Their product rotates the two-component state by 2 theta; D is the reflection about the prepared uniform state. Read each circuit left to right.One pair of reflections|s⟩O_fDsinθ|G⟩+cosθ|B⟩longmapstosin(3θ)|G⟩+cos(3θ)|B⟩
Geometry of Grover search in the \(\ket{B}\)–\(\ket{G}\) plane for a single marked item (\(\sin\theta = 1/\sqrt{N}\)). The oracle \(O_f\) reflects the state across the horizontal axis \(\ket{B}\), and the diffusion step \(D\) reflects it across \(\ket{s}\) (at angle \(\theta\)). Together, each Grover iteration \(DO_f\) rotates the state vector counterclockwise by \(2\theta\) toward \(\ket{G}\).
What to observe

Starting at \(30^\circ\) for \(N=4\), \(O_f\) reflects the state to \(-30^\circ\) and \(D\) reflects it to \(90^\circ\) (the marked axis, probability \(1\)). A second iteration adds another \(60^\circ\) rotation to \(150^\circ\), reducing the success probability to \(\sin^2 150^\circ=1/4\).

Problems
  1. For \(N=16\) and \(M=1\), by how many degrees does each Grover iteration rotate the state?

    Show solutionHide solution

    By \(2\theta\approx29^\circ\), where \(\sin\theta=1/4\).

  2. For \(N=16\) and \(M=1\), give the angle of the state and the success probability after \(1\), \(2\), \(3\), and \(4\) iterations.

    Show solutionHide solution

    The angle after \(k\) iterations is \((2k+1)\theta\), with \(\theta\approx14.48^\circ\): about \(43.4^\circ\), \(72.4^\circ\), \(101.3^\circ\), and \(130.3^\circ\). The success probabilities \(\sin^2\) of these angles are about \(0.47\), \(0.91\), \(0.96\), and \(0.58\). The best is three iterations; the fourth overshoots.

  3. In the plane with the bad direction as the first axis and the good direction as the second, reflection across the line at angle \(\alpha\) is \(\begin{pmatrix}\cos2\alpha&\sin2\alpha\\\sin2\alpha&-\cos2\alpha\end{pmatrix}\). Verify that reflecting across the bad axis and then across \(\ket s\) is a rotation by \(2\theta\).

    Show solutionHide solution

    The first reflection, across \(\alpha=0\), is \(\operatorname{diag}(1,-1)\). The second, across \(\alpha=\theta\), multiplies it on the left: \(\begin{pmatrix}\cos2\theta&\sin2\theta\\\sin2\theta&-\cos2\theta\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix}=\begin{pmatrix}\cos2\theta&-\sin2\theta\\\sin2\theta&\cos2\theta\end{pmatrix}\), the rotation by \(2\theta\).

9.3

Grover Iteration

Because each Grover iteration rotates the state vector by a constant angle \(2\theta\) in the \(\ket{B}\)–\(\ket{G}\) plane, we can write down the exact state vector and success probability after any number of iterations \(k\). This formula tells us when to stop the rotation to maximize the probability of finding a marked item, explains why continuing past the peak causes overshooting, and shows how to handle searches when the number of marked items \(M\) is unknown in advance.

9.3.1 Amplitude evolution§

Starting from \(\ket{\psi_0} = \ket{s}\) at angle \(\theta\) above \(\ket{B}\), each Grover iteration \(DO_f\) adds \(2\theta\) to the angle. After \(k\) Grover iterations, the state vector \(\ket{\psi_k} = (DO_f)^k\ket{s}\) sits at angle \((2k+1)\theta\) above \(\ket{B}\):

\[\ket{\psi_k} = \sin\bigl((2k+1)\theta\bigr)\,\ket{G} + \cos\bigl((2k+1)\theta\bigr)\,\ket{B}.\]

Measuring the register after \(k\) iterations yields a marked item with probability equal to the squared vertical component:

\[p_k = \sin^2\bigl((2k+1)\theta\bigr).\]

Which marked item is returned when \(M \gt 1\)? Because \(\ket{G} = \frac{1}{\sqrt{M}}\sum_{f(x)=1}\ket{x}\) weights all \(M\) marked strings equally, the measurement returns one of the \(M\) marked strings chosen uniformly at random, each with probability \(p_k/M\). Notice that the overall success probability \(p_k\) depends solely on the marked fraction \(M/N\) (which fixes \(\theta = \arcsin\sqrt{M/N}\)), never on which specific strings are marked.

Repeated Grover iterationsThe repeated gate denotes k uses of the oracle-and-reflection pair, not one elementary gate. Measure only after these coherent iterations. Read each circuit left to right.Repeated Grover iterations|0ⁿ⟩xH^(⊗ n)(DO_f)ᵏMpₖ=sin²((2k+1)θ), sin²θ=M/N
The repeated gate denotes k uses of the oracle-and-reflection pair, not one elementary gate. Measure only after these coherent iterations.
Problems
  1. For \(N=16\) and \(M=1\), compute \(p_k=\sin^2\bigl((2k+1)\theta\bigr)\) for \(k=0\) and \(k=3\).

    Show solutionHide solution

    With \(\sin\theta=1/4\): \(p_0=1/16\), and \(p_3=\sin^2(7\theta)\approx\sin^2(101.3^\circ)\approx0.96\).

  2. For \(N=64\) and \(M=1\), which number of iterations maximizes the success probability, and what is that probability?

    Show solutionHide solution

    \(\sin\theta=1/8\), so \(\theta\approx7.18^\circ\), and \(\pi/(4\theta)-1/2\approx5.8\). Comparing neighbours: \(k=5\) gives \(\sin^2(79^\circ)\approx0.96\), and \(k=6\) gives \(\sin^2(93.4^\circ)\approx0.997\). The best is \(k=6\), with success probability about \(0.997\).

  3. Show that, given success, the measured label is uniformly distributed over the \(M\) marked labels, and that, given failure, it is uniform over the unmarked labels.

    Show solutionHide solution

    The state is always \(\sin\bigl((2k+1)\theta\bigr)\ket G+\cos\bigl((2k+1)\theta\bigr)\ket B\), and \(\ket G\) gives every marked label the same amplitude \(1/\sqrt M\). So all marked labels have equal probability \(\sin^2\bigl((2k+1)\theta\bigr)/M\), and given success each has probability \(1/M\). The same argument with \(\ket B\) applies to failure.

9.3.2 Iteration count and overshooting§

overshootingstopping rule

To make the success probability \(p_k = \sin^2\bigl((2k+1)\theta\bigr)\) as close to \(1\) as possible, we want the angle \((2k+1)\theta\) to land as close as possible to \(\pi/2\) (\(90^\circ\)), where the state vector aligns with \(\ket{G}\):

\[(2k+1)\theta \approx \frac{\pi}{2} \quad\Longrightarrow\quad k \approx \frac{\pi}{4\theta} - \frac{1}{2}.\]

Rounding to the nearest nonnegative integer \(k = \lfloor \pi/(4\theta)\rfloor\) places the state vector within angle \(\theta\) of the vertical axis \(\ket{G}\), guaranteeing a success probability of at least \(1 - \sin^2\theta = 1 - M/N\). When the marked fraction \(M/N\) is small (\(M \ll N\)), \(\sin\theta \approx \theta = \sqrt{M/N}\), so the optimal number of Grover iterations is

\[k \approx \frac{\pi}{4}\sqrt{\frac{N}{M}}.\]

Instead of the roughly \(N/M\) queries required by classical search, Grover's algorithm finds a marked item with high probability using only about \(\frac{\pi}{4}\sqrt{N/M}\) quantum queries—a quadratic speedup! For example, searching \(N = 1{,}000{,}000\) items for \(M = 1\) marked item takes roughly \(785\) Grover iterations instead of hundreds of thousands of classical queries.

Note two important subtleties. First, while \(N=4, M=1\) (\(\theta = \pi/6\)) happens to hit \((2k+1)\theta = \pi/2\) exactly at \(k=1\) (giving \(p_1 = 1\)), for most values of \(N\) the discrete steps \((2k+1)\theta\) step slightly past or short of \(\pi/2\): for \(N=16, M=1\) (\(\theta = \arcsin(1/4) \approx 14.48^\circ\)), \(k=3\) iterations reach \(7\theta \approx 101.4^\circ\), giving success probability \(\sin^2(101.4^\circ) \approx 0.961\). Second, unlike classical search—where testing more candidates can only increase the chance of finding the mark—running Grover's algorithm for too many iterations causes overshooting: the state vector rotates right past \(\ket{G}\) and back down toward \(-\ket{B}\), causing the success probability to plummet! In our four-item search, \(k=1\) gives \(p_1 = 1\), but \(k=2\) rotates to \(150^\circ\) where \(p_2 = 1/4\), and \(k=3\) rotates to \(210^\circ\) where \(p_3 = 1/4\). Choosing the right stopping rule \(k\) is therefore an essential part of the algorithm.

Interactive figure. This simulator runs Grover’s search iteration from a uniform superposition and plots the marked-state probability after each step. Set the search space size to 4, step through one and two iterations, and observe how over-rotation affects the success probability.

What to observe

On a 4-item search space, one iteration rotates the state directly onto the marked item with probability \(1\), whereas a second iteration over-rotates the state and drops the success probability back to \(1/4\).

Problems
  1. For \(N=4\) and \(M=1\), compute the success probability after three iterations.

    Show solutionHide solution

    \(\theta=30^\circ\), so the angle is \(7\theta=210^\circ\), and \(\sin^2210^\circ=1/4\): no better than guessing.

  2. A search has \(N=16\) items. You plan three Grover iterations assuming one marked item, but there are actually four. What success probability do three iterations give? How many iterations would work if you knew there were four?

    Show solutionHide solution

    With \(M=4\), \(\sin\theta=\sqrt{4/16}=1/2\), so \(\theta=\pi/6\). Three iterations give \(\sin^2(7\pi/6)=1/4\). One iteration gives \(\sin^2(3\pi/6)=1\). More marked items do not guarantee better performance with a fixed iteration count: they change the rotation angle, so the stopping time must change too.

  3. Show that the sequence of success probabilities \(p_0,p_1,p_2,\dots\) is periodic when \(\theta\) is a rational multiple of \(\pi\), and find the period for \(N=4\), \(M=1\).

    Show solutionHide solution

    \(p_k=\sin^2\bigl((2k+1)\theta\bigr)\), and \(\sin^2\) repeats when its argument changes by \(\pi\). Each iteration adds \(2\theta\), so \(p_{k+j}=p_k\) whenever \(2j\theta\) is a multiple of \(\pi\). For \(\theta=\pi/6\), \(2j\theta=j\pi/3\), first a multiple of \(\pi\) at \(j=3\). The sequence is \(\tfrac14,1,\tfrac14,\tfrac14,1,\tfrac14,\dots\), with period \(3\).

9.3.3 Unknown marked fraction and verification§

verification

What if we do not know in advance how many items \(M\) are marked? Without knowing \(M\), we do not know the angle \(\theta = \arcsin\sqrt{M/N}\), and if we guess \(M=1\) when \(M\) is actually large, running \(\frac{\pi}{4}\sqrt{N}\) iterations may wildly overshoot \(\ket{G}\)! Fortunately, because we can perform verification on any candidate string \(x\) returned by measurement using a single classical query \(f(x)\), we can use an exponentially growing randomized schedule: in round \(r = 1, 2, 3, \dots\), pick a random iteration count \(k\) uniformly between \(0\) and \(\lceil c^r\rceil\) (for a constant such as \(c = 6/5\)), run \(k\) Grover iterations, measure a candidate \(x\), and check whether \(f(x)=1\). Once \(c^r\) reaches the scale of \(1/\theta \approx \sqrt{N/M}\), the average of \(\sin^2\bigl((2k+1)\theta\bigr)\) over the range is near \(1/2\), so the procedure finds and verifies a marked item using an expected total of only a constant multiple of \(\sqrt{N/M}\) queries—preserving the quadratic speedup without knowing \(M\)!

What if \(M = 0\) (no item is marked at all)? Then \(O_f = I\), the state never moves from \(\ket{s}\), and no candidate ever passes verification. Once the randomized schedule has expended a fixed multiple of \(\sqrt{N}\) queries without finding a marked item, the algorithm halts and reports that no marked item exists, with an arbitrarily small bounded probability of error if a marked item was actually present.

(At the opposite extreme, if all \(N\) items are marked, \(M=N\), the very first candidate checked before any Grover iterations immediately passes verification with certainty.)

Further detail: Boyer, Brassard, Høyer, and Tapp: Tight bounds on quantum searching.

Verify a measured candidateAfter a search run returns candidate x, a separate basis-input query checks it. A failed check calls for another run with the prescribed iteration schedule and budget. Read each circuit left to right.Verify a measured candidate|0ⁿ⟩xH^(⊗ n)(DO_f)ᵏMVerification run|x⟩|0⟩f(x)U_fMAccept only when the measured predicate bit is 1.
After a search run returns candidate x, a separate basis-input query checks it. A failed check calls for another run with the prescribed iteration schedule and budget.
Problems
  1. An algorithm succeeds with probability \(p\) per attempt and checks its candidate with one query. How many attempts does it need on average to find a marked label?

    Show solutionHide solution

    The attempts are independent, so the number needed is geometric with mean \(1/p\). Because each candidate is checked, the algorithm never reports a wrong label.

  2. For \(N=1024\), the iteration count tuned for \(M=1\) is \(k=25\). What is the success probability if in fact \(M=4\)?

    Show solutionHide solution

    For \(M=4\), \(\sin\theta=\sqrt{4/1024}=1/16\), and \(51\theta\approx51\times3.58^\circ\approx182.7^\circ\), so the success probability is \(\sin^2(182.7^\circ)\approx0.002\). Tuned for \(M=1\) it would be about \(0.999\). Guessing \(M\) wrong can make the search almost certain to fail.

  3. Each verified attempt succeeds with probability at least \(1/4\), independently. Show that \(t\) attempts all fail with probability at most \((3/4)^t\), and find the smallest \(t\) for which this is below \(10^{-6}\).

    Show solutionHide solution

    Each attempt fails with probability at most \(3/4\), and independent failures multiply, so all \(t\) fail with probability at most \((3/4)^t\). We need \(t\ln(3/4)\lt\ln10^{-6}\), that is, \(t\gt\ln10^{-6}/\ln(3/4)\approx48.0\), so \(t=49\).

9.4

General Amplitude Amplification

Did the two-reflection geometry of Grover's algorithm depend on starting from the uniform superposition \(\ket{s} = H^{\otimes n}\ket{0^n}\)? Not at all! Any unitary circuit \(A\) that prepares a state \(\ket{\psi} = A\ket{0^n}\) having nonzero probability \(p\) of landing in a "good" subspace can be boosted by alternating reflections across the good subspace and across \(\ket{\psi}\)—a general technique called amplitude amplification that reduces the number of trials from roughly \(1/p\) to roughly \(1/\sqrt{p}\).

9.4.1 Arbitrary state preparation§

Suppose we have a unitary circuit \(A\) (which might be a quantum heuristic or a coherent version of a randomized classical algorithm) that maps the all-zero state \(\ket{0^n}\) to \(\ket{\psi} = A\ket{0^n}\). Suppose further that a projector \(P_G\) identifies the "good" (successful) measurement outcomes, and that measuring \(\ket{\psi}\) directly succeeds with probability \(p = \|P_G\ket{\psi}\|^2\), where \(0 \lt p \lt 1\). By normalizing the good projection \(P_G\ket{\psi}\) into \(\ket{G}\) and the orthogonal bad projection \((I - P_G)\ket{\psi}\) into \(\ket{B}\), we can write \(\ket{\psi}\) in the exact same two-dimensional plane as before:

\[\ket{\psi} = \sqrt{p}\,\ket{G} + \sqrt{1-p}\,\ket{B} = \sin\theta\,\ket{G} + \cos\theta\,\ket{B},\qquad \sin^2\theta = p.\]

Notice that Grover search is simply the special case where \(A = H^{\otimes n}\) prepares the uniform superposition \(\ket{s}\) and \(p = M/N\).

Where might a general preparation circuit \(A\) come from? If a randomized classical algorithm solves a problem with small success probability \(p\) using random coin flips and reversible logic, we can replace its random bits with qubits initialized in \(\ket{+}\) and run its reversible circuit coherently as \(A\)—provided we uncompute any temporary workspace so the branches remain coherent.

An arbitrary coherent preparationA is the full reversible preparation circuit. Its success probability is the total weight on good outputs; the bundled wire includes any required coherent workspace. Read each circuit left to right.An arbitrary coherent preparation|0ⁿ⟩xAMA|0⟩=√p|G⟩+√(1−p)|B⟩
A is the full reversible preparation circuit. Its success probability is the total weight on good outputs; the bundled wire includes any required coherent workspace.
Problems
  1. A preparation succeeds with probability \(p=1/9\). Find \(\theta\) and the amplitudes of \(\ket G\) and \(\ket B\).

    Show solutionHide solution

    \(\sin\theta=\sqrt p=1/3\), so \(\theta\approx19.5^\circ\). The amplitudes are \(\sqrt p=1/3\) and \(\sqrt{1-p}=2\sqrt2/3\).

  2. For \(p=1/9\), how many amplification iterations maximize success, and what is the success probability?

    Show solutionHide solution

    The angle after \(k\) iterations is \((2k+1)\theta\): about \(58.4^\circ\) for \(k=1\) and \(97.4^\circ\) for \(k=2\). The success probabilities are about \(0.73\) and \(0.98\), so \(k=2\) is best.

  3. A one-qubit preparation \(A\) gives \(A\ket0=\tfrac{\sqrt3}2\ket0+\tfrac12\ket1\), and success means outcome \(1\). Show that one amplification iteration succeeds with certainty, even though this preparation is not uniform.

    Show solutionHide solution

    \(p=1/4\), so \(\theta=30^\circ\), and one iteration turns the state to \(90^\circ\), the good direction. Directly: \(I-2P_G=Z\) gives \(\ket v=\tfrac{\sqrt3}2\ket0-\tfrac12\ket1\). Then \(R_\psi\ket v=2\ket\psi\braket\psi v-\ket v\) with \(\braket\psi v=\tfrac34-\tfrac14=\tfrac12\), giving \(\ket\psi-\ket v=\ket1\).

9.4.2 Reflection using preparation and its inverse§

coherent access

To rotate \(\ket{\psi}\) toward \(\ket{G}\) in the \(\ket{B}\)–\(\ket{G}\) plane, we need two reflections: first, the phase oracle \(O_G = I - 2P_G\) that negates \(\ket{G}\) and preserves \(\ket{B}\); second, the reflection \(R_\psi = 2\ketbra{\psi}{\psi} - I\) across the prepared state \(\ket{\psi}\). How can we implement a reflection across \(\ket{\psi} = A\ket{0^n}\) when \(\ket{\psi}\) is a complicated state produced by the circuit \(A\)?

Just as we conjugated \(2\ketbra{0^n}{0^n} - I\) by \(H^{\otimes n}\) in Section 8.2.3, we simply conjugate the all-zero reflection \(2\ketbra{0^n}{0^n} - I\) by \(A\) and its adjoint \(A^\dagger\):

\[R_\psi = 2\ketbra{\psi}{\psi} - I = 2(A\ket{0^n})(\bra{0^n}A^\dagger) - AA^\dagger = A\bigl(2\ketbra{0^n}{0^n} - I\bigr)A^\dagger.\]

Reading the operator product from right to left shows how \(R_\psi\) works in three steps: first apply the inverse circuit \(A^\dagger\) (which maps \(\ket{\psi}\) back to \(\ket{0^n}\)), then apply the standard reflection \(2\ketbra{0^n}{0^n} - I\) about the all-zero state \(\ket{0^n}\), and finally apply the forward preparation circuit \(A\) (which maps \(\ket{0^n}\) back to \(\ket{\psi}\)).

Crucially, this construction requires coherent access to the unitary preparation circuit \(A\), its inverse circuit \(A^\dagger\), and the phase-marking oracle \(O_G\). Having a classical black box that merely outputs random samples from \(\ket{\psi}\) is not enough: measuring after \(A\) collapses the state vector and prevents the reflection \(R_\psi\) from rotating amplitudes.

Reflection about a prepared stateApply A dagger, reflect about the all-zero state, then apply A. Operations act from left to right.|v⟩A†2|0⟩⟨0|−IAResult: (2|ψ⟩⟨ψ|−I)|v⟩, where |ψ⟩=A|0⟩
Implementing the reflection \(R_\psi = A(2\ketbra{0^n}{0^n}-I)A^\dagger\) about \(\ket{\psi} = A\ket{0^n}\): run the inverse circuit \(A^\dagger\) first, reflect about \(\ket{0^n}\), and run the forward preparation \(A\).
Problems
  1. For \(A=H\) on one qubit, write \(R_\psi=A(2\ket0\bra0-I)A^\dagger\) as a matrix.

    Show solutionHide solution

    Here \(\ket\psi=\ket+\), and \(R_\psi=2\ket+\bra+-I=\begin{pmatrix}1&1\\1&1\end{pmatrix}-I=\begin{pmatrix}0&1\\1&0\end{pmatrix}=X\).

  2. Show that \(A(2\ket0\bra0-I)A^\dagger=2\ket\psi\bra\psi-I\) when \(A\ket0=\ket\psi\), and that it is unitary.

    Show solutionHide solution

    \(A\ket0\bra0A^\dagger=(A\ket0)(A\ket0)^\dagger=\ket\psi\bra\psi\), and \(AIA^\dagger=AA^\dagger=I\), so the product is \(2\ket\psi\bra\psi-I\). It is a product of three unitaries, since \(2\ket0\bra0-I=\operatorname{diag}(1,-1,\dots,-1)\) is unitary, and so it is unitary.

  3. Why can the reflection \(R_\psi\) not be replaced by measuring whether the prepared state succeeded? Show that measuring after each oracle step makes the success probability stay at \(p\).

    Show solutionHide solution

    Measuring the prepared state \(\sqrt p\ket G+\sqrt{1-p}\ket B\) gives success with probability \(p\) and leaves a single outcome. Repeating preparation and measurement just gives independent trials, each with success \(p\). The reflection instead rotates the whole state toward \(\ket G\); measurement destroys the superposition that the rotation acts on.

9.4.3 Success probability and resource cost§

amplitude amplification

Let us compare classical repetition against quantum amplitude amplification. If a single run of a classical procedure succeeds with small probability \(p\), repeating independent classical trials requires roughly \(1/p\) runs to achieve a high probability of at least one success. By contrast, each round of amplitude amplification \(R_\psi O_G\) rotates the state vector by \(2\theta \approx 2\sqrt{p}\) toward \(\ket{G}\), reaching a success probability near \(1\) after only

\[k \approx \frac{\pi}{4\theta} \approx \frac{\pi}{4\sqrt{p}}\]

iterations—reducing the number of repetitions from order \(1/p\) to order \(1/\sqrt{p}\)!

To evaluate the total gate cost honestly, we must count the work performed inside each amplification round. Each round applies \(O_G\) once (at cost \(C_G\)) and \(R_\psi = A(2\ketbra{0^n}{0^n}-I)A^\dagger\) once (which runs both \(A\) and \(A^\dagger\), at cost roughly \(2C_A\)). Including the initial preparation \(A\), the total cost to reach high success probability scales as

\[\text{Total cost} \sim \frac{2C_A + C_G}{\sqrt{p}}.\]

This formula captures both the power and the engineering trade-offs of amplitude amplification: the denominator \(\sqrt{p}\) delivers the quadratic speedup in trial count, while the numerator \(2C_A + C_G\) reminds us that every iteration must pay the full coherent gate cost of preparing, uncomputing, and testing the state. In Chapter 10, we will prove that this \(\sqrt{N}\) scaling is not merely a feature of Grover's construction, but the absolute mathematical limit for any quantum search algorithm.

Pay for both preparation and its inverseOne amplification round applies the success reflection, inverse preparation, zero-state reflection, and preparation. Repeat the round coherently before measuring; the zero-reflection cost must also be included when significant. Read each circuit left to right.Pay for both preparation and its inverse|ψ⟩I−2P_GA†R₀AR₀=2|0⟩⟨0|−I; R_ψ=A R₀ A†One round costs C_G+2C_A+C_(R₀).
One amplification round applies the success reflection, inverse preparation, zero-state reflection, and preparation. Repeat the round coherently before measuring; the zero-reflection cost must also be included when significant.
Problems
  1. For \(p=0.01\), compare the number of independent trials needed for a reasonable chance of success with the number of amplification iterations.

    Show solutionHide solution

    Trials: about \(1/p=100\). Amplification: about \(\tfrac\pi4/\sqrt p\approx8\) iterations, each using \(A\), \(A^\dagger\), and the success test.

  2. Preparing \(A\) costs \(100\) gates and the success test \(20\) gates. For \(p=10^{-4}\), compare the total cost of about \(1/p\) independent trials, each a preparation and a test, with about \(\tfrac\pi4/\sqrt p\) amplification iterations, each using \(A\), \(A^\dagger\), and the test.

    Show solutionHide solution

    Trials: \(10^4\times120=1.2\times10^6\) gates. Amplification: \(\tfrac\pi4\times100\approx79\) iterations of \(100+100+20=220\) gates, about \(1.7\times10^4\) gates, roughly \(70\) times fewer.

  3. Preparing an arbitrary list of \(N\) amplitudes costs about \(N\) gates. For a search among \(N\) items with one marked item, so that \(p=1/N\), compare the cost of amplitude amplification with a classical scan of the list.

    Show solutionHide solution

    Amplification needs about \(\sqrt N\) iterations, and each uses the preparation, costing about \(N\), so the total is about \(N\sqrt N\). A classical scan of the list costs about \(N\). If the data must be loaded this way, amplification is slower: the advantage depends on the preparation being cheap.

Summary

Questions and worked problems

Attempt each question before opening a hint. Explain your reasoning, then compare it with the solution.

1. Quick check §

For \(N=32\) and \(M=2\), find \(\sin\theta\) and the initial success probability.

Hint 1

\(\sin^2\theta=M/N\).

Hint 2

Compare with \(N=16\), \(M=1\).

Worked solution

\(\sin\theta=\sqrt{2/32}=1/4\), and the initial success probability is \(1/16\), the same as for one marked item among sixteen.

Revisit the relevant explanation

2. Quick check §

For \(N=8\) with one marked item, find \(\theta\), the number of iterations \(k\) that maximizes the success probability, and that probability. What happens at \(k=3\)?

Hint 1

\(\sin\theta=1/\sqrt8\), so \(\theta\approx0.361\).

Hint 2

\(p_k=\sin^2((2k+1)\theta)\).

Worked solution

\(\theta=\arcsin(1/\sqrt8)\approx0.361\) rad (about \(20.7^\circ\)), and \(\frac{\pi}{4\theta}-\frac12\approx1.67\), so \(k=2\). The success probabilities for \(k=0,1,2,3\) are about \(0.125,\ 0.781,\ 0.945,\ 0.330\). The best choice gives \(0.945\) with two oracle queries, against a classical guess-and-check that needs about four queries for even a \(50\%\) chance. At \(k=3\) the state has rotated past the good direction, and the success probability falls to \(0.33\).

Revisit the relevant explanation

3. Quick check §

For \(N=4\) with three marked items, find \(\theta\) and the success probability before and after one Grover iteration. What should a search algorithm do when most items are marked?

Hint 1

\(\sin\theta=\sqrt{3/4}\), so \(\theta=\pi/3\).

Hint 2

After one iteration the angle is \(3\theta\).

Worked solution

\(\sin\theta=\sqrt3/2\) gives \(\theta=\pi/3\), and the initial success probability is \(\frac34\). One iteration turns the state to \(3\theta=\pi\), so \(p_1=\sin^2\pi=0\): every outcome is unmarked. The state started closer to the good direction than one rotation step, and the rotation overshot completely. When the marked fraction is large, a random guess already succeeds with high probability, so the algorithm should simply sample and check. The randomized schedules of Section 9.3.3 include zero iterations among their choices, which covers this case.

Revisit the relevant explanation

4. Worked problem §

For \(N=32\) and \(M=2\), find the number of Grover iterations that maximizes success, and the success probability.

Hint 1

The angle is the same as for \(N=16\), \(M=1\).

Hint 2

Compute \(\sin^2((2k+1)\theta)\) for \(k=2,3,4\).

Worked solution

With \(\theta\approx14.48^\circ\), the success probabilities for \(k=2,3,4\) are about \(0.91\), \(0.96\), and \(0.58\). The best is \(k=3\), with success about \(0.96\). Only the marked fraction matters, not \(N\) or \(M\) separately.

Revisit the relevant explanation

5. Worked problem §

A one-qubit preparation \(A\) gives \(A\ket0=\cos\alpha\ket0+\sin\alpha\ket1\) with \(\alpha=\pi/10\), and success means outcome \(1\). (a) Find \(p\) and \(\theta\). (b) How many amplification iterations give certain success? (c) How many independent trials of \(A\) are needed for success probability \(0.99\), and how do the two counts of calls to \(A\) or \(A^\dagger\) compare?

Hint 1

Here \(\theta=\alpha\).

Hint 2

Require \((2k+1)\theta=\pi/2\). Each iteration uses \(A\) and \(A^\dagger\) once.

Worked solution

(a) \(p=\sin^2(\pi/10)\approx0.0955\) and \(\theta=\pi/10\). (b) \((2k+1)\frac{\pi}{10}=\frac\pi2\) gives \(k=2\), so two iterations succeed with certainty. (c) Independent trials fail with probability \((1-p)^t\le e^{-pt}\). Requiring \(e^{-pt}\le0.01\) gives \(t\ge\ln100/0.0955\approx48\) trials. The amplified version uses one initial \(A\) plus, per iteration, one \(A^\dagger\) and one \(A\): five calls in all, together with two success reflections. A non-uniform preparation is amplified exactly like search, because only the angle \(\theta\) matters.

Revisit the relevant explanation

6. Worked problem §

When \(M\) is unknown, choose the number of iterations \(k\) uniformly from \(\{0,1,2,3\}\). For \(N=16\), compute the average success probability when \(M=1\) and when \(M=4\). Why does a random choice protect against not knowing \(M\)?

Hint 1

For \(M=1\), \(\theta\approx0.2527\); for \(M=4\), \(\theta=\pi/6\).

Hint 2

Average \(\sin^2((2k+1)\theta)\) over the four values of \(k\).

Worked solution

For \(M=1\), the probabilities for \(k=0,\dots,3\) are about \(0.063,\ 0.473,\ 0.908,\ 0.961\), averaging \(0.60\). For \(M=4\), they are \(0.25,\ 1,\ 0.25,\ 0.25\), averaging \(0.44\). A fixed choice tuned for \(M=1\), namely \(k=3\), would give only \(0.25\) when \(M=4\), and the choice tuned for \(M=4\), \(k=1\), gives \(0.47\) when \(M=1\). Averaged over a range of \(k\), \(\sin^2\) of a steadily advancing angle is close to \(\frac12\) once the range covers about a quarter turn. So each random attempt succeeds with constant probability for every \(M\) in the range, and checking the candidate with one query confirms success. Growing the range gradually keeps the total query count of order \(\sqrt{N/M}\).

Revisit the relevant explanation

7. Worked problem §

Two preparations are available for the same search task, each with a \(20\)-gate success test. \(A_1\) costs \(10\) gates and succeeds with \(p_1=10^{-6}\); \(A_2\) costs \(1000\) gates and succeeds with \(p_2=10^{-3}\). Using the estimate \((C_A+C_G)/p\) for classical repetition and \((2C_A+C_G)/\sqrt p\) for amplitude amplification, compare the costs of both preparations under both strategies.

Hint 1

\(1/\sqrt{10^{-6}}=1000\) and \(1/\sqrt{10^{-3}}\approx31.6\).

Hint 2

Compute four numbers and compare within each strategy.

Worked solution

Classical repetition: \(A_1\) costs \(30\times10^6=3\times10^7\) gates; \(A_2\) costs \(1020\times10^3\approx1.0\times10^6\). The expensive but better preparation wins by a factor of about \(30\). Amplification: \(A_1\) costs \(40\times1000=4\times10^4\); \(A_2\) costs \(2020\times31.6\approx6.4\times10^4\). Now the cheap preparation wins. Amplification takes a square root of \(1/p\) but pays the preparation cost in full each round, so improvements in \(p\) are worth less than they are classically. The best design depends on the whole cost formula, not on the success probability alone.

Revisit the relevant explanation

8. Misconception §

A student says: “Grover search always finds the marked item with certainty if you choose the right number of iterations.” Test the claim for \(N=16\), \(M=1\). What condition on \(\theta\) would certainty require, and what is known about when it can hold for one marked item?

Hint 1

Certainty requires \((2k+1)\theta=\pi/2\) for some integer \(k\).

Hint 2

For \(N=16\), the best success probability is at \(k=3\).

Worked solution

For \(N=16\), the success probabilities are about \(0.063,0.473,0.908,0.961,0.582,\dots\), so the best is \(0.961\) at \(k=3\), not \(1\). Certainty needs \((2k+1)\theta=\pi/2\) exactly, that is \(\sin^2\big(\pi/(4k+2)\big)=M/N\). With \(M=1\) the right side is \(1/N\), a rational number. By a theorem of Niven, the only rational values of \(\sin^2\) at rational multiples of \(\pi\) are \(0,\frac14,\frac12,\frac34,1\), so among \(N\ge2\) only \(N=4\) gives certainty with standard iterations. Grover’s algorithm guarantees success probability at least \(1-M/N\) at the best \(k\). Exact success is possible, but it needs modified phases in the final iteration, a technique developed in Quantum Algorithms.

Revisit the relevant explanation

9. Extension §

For \(N=4\) with two marked items, show that Grover iterations never change the success probability.

Hint 1

Find \(\theta\) from \(\sin^2\theta=1/2\).

Hint 2

Compute \(\sin^2((2k+1)\theta)\).

Worked solution

\(\theta=45^\circ\), so the angles \((2k+1)45^\circ\) are odd multiples of \(45^\circ\), and \(\sin^2\) of every one is \(1/2\). Iterating never helps: when half the items are marked, a random guess is already as good as the algorithm can do.

Revisit the relevant explanation

10. Extension §

Prove the guarantee behind the stopping rule. Let \(k\) be the integer nearest to \(\frac{\pi}{4\theta}-\frac12\). (a) Show that \((2k+1)\theta\) lies within \(\theta\) of \(\pi/2\). (b) Deduce \(p_k\ge\cos^2\theta=1-M/N\). (c) Show that \(k\le\frac\pi4\sqrt{N/M}\), using \(\theta\ge\sin\theta\).

Hint 1

Rounding changes \(k\) by at most \(\frac12\), so \((2k+1)\theta\) changes by at most \(\theta\).

Hint 2

If an angle \(\varphi\) satisfies \(|\varphi-\pi/2|\le\theta\), then \(\sin^2\varphi\ge\cos^2\theta\).

Worked solution

(a) Let \(k^*=\frac{\pi}{4\theta}-\frac12\), so \((2k^*+1)\theta=\frac\pi2\) exactly. The nearest integer satisfies \(|k-k^*|\le\frac12\), so \(|(2k+1)\theta-\frac\pi2|=2\theta|k-k^*|\le\theta\). (b) Writing \(\varphi=(2k+1)\theta=\frac\pi2+\delta\) with \(|\delta|\le\theta\), we get \(\sin^2\varphi=\cos^2\delta\ge\cos^2\theta=1-\sin^2\theta=1-M/N\), since \(\theta<\pi/2\). (c) \(k\le k^*+\frac12=\frac{\pi}{4\theta}\le\frac{\pi}{4\sin\theta}=\frac\pi4\sqrt{N/M}\). So at most \(\frac\pi4\sqrt{N/M}\) queries achieve success probability at least \(1-M/N\), which is the quantitative form of the quadratic speedup for search.

Revisit the relevant explanation

Where this leads. Chapter 10 compares query savings with gate costs and lower bounds.

Search this book

Search all chapters and appendices.