|q⟩ Bad Qubits

advanced · Physics · Quantum Complexity Theory

Quantum Query Complexity

Many quantum speedups are cleanest to state in the query model, where the input is not given as a string but as a black box (an oracle) that we may probe. The cost of an algorithm is the number of oracle calls it makes, and lower bounds in this model are the strongest unconditional separations we have between quantum and classical computation. This lesson sets up the model and works through its flagship example, Grover's unstructured search.

The query (oracle) model

The input is a function f:{0,1}n{0,1}f : \{0,1\}^n \to \{0,1\} accessible only through a unitary oracle. The standard phase oracle acts as

Ofx=(1)f(x)x,O_f \ket{x} = (-1)^{f(x)} \ket{x},

flipping the sign of marked inputs. (The equivalent bit oracle xbxbf(x)\ket{x}\ket{b} \mapsto \ket{x}\ket{b\oplus f(x)} produces the phase via a \ket{-} target qubit.) A quantum query algorithm interleaves arbitrary input-independent unitaries with calls to OfO_f:

ψfinal=UqOfUq1OfU1OfU000,\ket{\psi_{\text{final}}} = U_q\, O_f\, U_{q-1}\, O_f\, \cdots\, U_1\, O_f\, U_0 \ket{0\cdots 0},

then measures. The quantum query complexity of a problem is the least qq for which some such algorithm solves it with bounded error. We deliberately ignore the cost of the UiU_i — the model isolates how much information about ff is needed, which is why its lower bounds are unconditional.

Unstructured search and Grover

Suppose exactly one input ww is marked (f(w)=1f(w)=1, all others 00) and we want to find ww. Classically there is no structure to exploit: any deterministic algorithm must in the worst case probe N1N-1 of the N=2nN = 2^n inputs before it can be certain, and a randomized algorithm needs Θ(N)\Theta(N) queries on average. Search is the prototypical hard, structureless problem.

Grover's algorithm finds ww with O(N)O(\sqrt{N}) queries — a quadratic speedup. The mechanism is a rotation in a two-dimensional plane. Let

good=w,bad=1N1xwx,\ket{\text{good}} = \ket{w}, \qquad \ket{\text{bad}} = \frac{1}{\sqrt{N-1}}\sum_{x \ne w}\ket{x},

so the uniform superposition s=Hn0\ket{s} = H^{\otimes n}\ket{0} lives in their span and makes a small angle θ\theta with bad\ket{\text{bad}}, where

sinθ=ws=1N.\sin\theta = \braket{w | s} = \frac{1}{\sqrt N}.

One Grover iteration = a rotation by 2θ

A Grover iteration is G=(2ssI)OfG = (2\ket{s}\bra{s} - I)\,O_f: the oracle reflects the state about bad\ket{\text{bad}} (it flips the sign of the w\ket{w} component), and the diffusion operator 2ssI2\ket{s}\bra{s}-I reflects about s\ket{s}. The composition of two reflections is a rotation, by twice the angle between the mirrors, namely 2θ2\theta, toward good\ket{\text{good}}. Starting from s\ket{s} (angle θ\theta from bad\ket{\text {bad}}), after rr iterations the angle is (2r+1)θ(2r+1)\theta, so the amplitude on the marked item is

wGrs=sin((2r+1)θ),Psuccess(r)=sin2((2r+1)θ).\braket{w | G^r | s} = \sin\big((2r+1)\theta\big), \qquad P_{\text{success}}(r) = \sin^2\big((2r+1)\theta\big).

Choosing the number of iterations

Success is maximized when (2r+1)θπ/2(2r+1)\theta \approx \pi/2, i.e.

rπ4θ12π4N(since θ1/N for large N).r^* \approx \frac{\pi}{4\theta} - \frac12 \approx \frac{\pi}{4}\sqrt{N} \quad\text{(since } \theta \approx 1/\sqrt N \text{ for large } N\text{)}.

We must round rr^* to an integer, which leaves a small residual error — for N=16N=16, θ=arcsin(1/4)\theta=\arcsin(1/4), the best integer is r=3r=3 giving Psuccess=sin2(7θ)0.961P_{\text{success}}=\sin^2(7\theta)\approx 0.961. Crucially, O(N)O(\sqrt N) queries suffice where classical search needs Θ(N)\Theta(N).

Why this is the best possible

The quadratic speedup is not an accident of the algorithm — it is optimal. The BBBV (Bennett–Bernstein– Brassard–Vazirani) theorem proves that any quantum algorithm needs Ω(N)\Omega(\sqrt N) queries to find a marked item among NN in the black-box setting. So Grover is tight, and search does not admit an exponential quantum speedup. This is also the central evidence that NP⊈BQP\mathsf{NP} \not\subseteq \mathsf{BQP}: brute-forcing an NP\mathsf{NP} search with Grover only halves the exponent, 2n2n/22^n \to 2^{n/2}, still exponential. The next lesson develops the lower-bound machinery (hybrid, polynomial, and adversary methods) behind such claims.

Try it

Compute, from first principles, the Grover parameters for N=16N=16 with one marked item: the rotation half-angle θ\theta, the optimal integer iteration count rr^*, the resulting success probability, the classical worst-case query count, and the speedup ratio. return the object { theta, rOpt, pSuccess, classicalWorst, speedup }.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.