Counting Solutions
Grover's algorithm searches for one or more marked items but requires you to know — the number of solutions — in advance so that you can run the right number of iterations. Quantum counting removes that assumption by estimating directly, using phase estimation on the Grover iterate.
The spectrum of the Grover iterate
Every Grover iteration is a rotation by in the two-dimensional plane spanned by the good and bad states, where
Because is a rotation by exactly , its eigenvalues are the complex numbers (Nielsen and Chuang, §6.3). Quantum phase estimation (QPE) can extract from these eigenvalues. Once we have an estimate of , the number of marked items follows from inverting the formula:
The counting circuit
The full quantum counting algorithm uses two registers:
- A phase register of ancilla qubits prepared in . More ancilla qubits give a more accurate estimate of .
- A target register of data qubits initialised to the uniform superposition (an approximate eigenstate of ).
Controlled applications of entangle the phase register with the eigenvalue. An inverse QFT on the phase register then concentrates probability on the bitstring nearest to . Reading that bitstring gives and therefore .
Error analysis
With ancilla qubits the estimate satisfies . The resulting error in is bounded by
which decreases exponentially as grows (Nielsen and Chuang, §6.3). For a given absolute precision it suffices to take ancilla qubits.
A worked example
Take qubits so , with marked item. Then
A phase estimation run that perfectly resolves returns . Plugging into the counting formula:
The estimate is exact here because is a rational multiple of and can be represented exactly.
Try it
The exercise asks you to implement the counting formula. You are given and a QPE output — compute and return the estimated number of marked items.
Sign in on the full site to ask questions and join the discussion.