Author @mujirin Verifier - Public

Why Grover’s Oracle Count Scales Like \(O\!\left(\sqrt{\frac{N}{M}}\right)\)

The expression

\[ O\left(\sqrt{\frac{N}{M}}\right) \]

appears in the parent document in the discussion of Grover’s algorithm. It describes the number of oracle calls needed, up to constant factors, to find a marked solution with high probability when there are \(N\) possible candidates and \(M\) of them are solutions.

This is not a statement about the cost of building the oracle. It is a statement about query complexity: how many times Grover’s algorithm must call the marking oracle once such an oracle is available. The parent document directly supports this interpretation by saying that Grover’s algorithm alternates between a phase oracle and a diffusion operator, and that after about this many oracle calls, measuring gives a solution with high probability. The deeper reasoning behind the formula comes from amplitude amplification.

The Search Setting

Suppose there is a finite search space of size \(N\). We can label its elements as basis states

\[ \ket{0},\ket{1},\dots,\ket{N-1}. \]

Among these \(N\) candidates, exactly \(M\) are solutions. The oracle is usually represented by a Boolean function

\[ f(x)= \begin{cases} 1, & x \text{ is a solution},\\ 0, & x \text{ is not a solution}. \end{cases} \]

The corresponding phase oracle acts as

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

So solution states receive a minus sign, while non-solution states remain unchanged. This phase flip is not itself the answer. Its role is to create a relative phase difference that the rest of the algorithm can turn into increased probability of measuring a solution.

Grover’s algorithm usually begins in the uniform superposition

\[ \ket{s} = \frac{1}{\sqrt{N}}\sum_{x=0}^{N-1}\ket{x}. \]

In this state, every candidate has equal probability \(1/N\). Since \(M\) of the \(N\) candidates are good, the initial probability of measuring a solution is

\[ \frac{M}{N}. \]

Classically, if one samples uniformly at random and checks candidates, one expects to need on the order of

\[ \frac{N}{M} \]

queries to find a solution. Grover’s algorithm improves this to roughly the square root,

\[ \sqrt{\frac{N}{M}}. \]

The highlighted expression is this quadratic improvement.

Compressing the Search Space into Two Directions

The cleanest way to understand the formula is to notice that Grover’s algorithm does not need to treat all \(N\) basis states separately. Because the oracle marks all solutions in the same way, and the diffusion operator treats all basis states symmetrically, the dynamics stay inside a two-dimensional subspace.

Define the normalized uniform superposition over good states:

\[ \ket{G} = \frac{1}{\sqrt{M}}\sum_{x:f(x)=1}\ket{x}. \]

Define the normalized uniform superposition over bad states:

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

assuming \(0<M<N\). These two states are orthogonal: \(\ket{G}\) lives entirely in the solution subspace, while \(\ket{B}\) lives entirely in the non-solution subspace.

The initial uniform state can be rewritten as a combination of these two directions:

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

This equation is the heart of the scaling. The coefficient of \(\ket{G}\) is

\[ \sqrt{\frac{M}{N}}. \]

That coefficient is the initial amplitude in the good direction. Its square,

\[ \left(\sqrt{\frac{M}{N}}\right)^2 = \frac{M}{N}, \]

is the initial probability of measuring a solution.

Grover’s algorithm amplifies amplitude, not probability directly. This is why a square root appears.

The Angle Behind the Formula

It is common to describe the initial state using an angle \(\theta\), defined by

\[ \sin \theta = \sqrt{\frac{M}{N}}. \]

Then

\[ \cos \theta = \sqrt{\frac{N-M}{N}}, \]

and the initial state becomes

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

If \(M\) is much smaller than \(N\), then \(\theta\) is small. For small angles,

\[ \sin\theta \approx \theta, \]

so

\[ \theta \approx \sqrt{\frac{M}{N}}. \]

A single Grover iteration consists of two reflections: the oracle reflection, which flips the phase of the good states, and the diffusion reflection, which reflects about the initial superposition. The product of two reflections is a rotation. In this two-dimensional \(\ket{G},\ket{B}\) plane, each Grover iteration rotates the state toward the good direction by an angle approximately \(2\theta\).

More precisely, after \(k\) Grover iterations, the state has the form

\[ \sin((2k+1)\theta)\ket{G} + \cos((2k+1)\theta)\ket{B}. \]

Therefore the probability of measuring a solution is

\[ \sin^2((2k+1)\theta). \]

To get high probability, we want the angle \((2k+1)\theta\) to be close to \(\pi/2\), because

\[ \sin^2\left(\frac{\pi}{2}\right)=1. \]

So we choose \(k\) such that

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

Solving roughly gives

\[ k \approx \frac{\pi}{4\theta}. \]

Since

\[ \theta \approx \sqrt{\frac{M}{N}}, \]

we get

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

Ignoring the constant factor \(\pi/4\), this becomes

\[ O\left(\sqrt{\frac{N}{M}}\right). \]

That is the origin of the highlighted expression.

What the Big-\(O\) Is Hiding

The notation

\[ O\left(\sqrt{\frac{N}{M}}\right) \]

does not claim that the exact number of oracle calls is equal to \(\sqrt{N/M}\). It means that the number of oracle calls grows no faster than a constant multiple of \(\sqrt{N/M}\), under the usual assumptions of Grover search.

A more precise estimate for the number of Grover iterations is often written as

\[ k \approx \left\lfloor \frac{\pi}{4}\sqrt{\frac{N}{M}} \right\rfloor \]

when \(M\ll N\). Each iteration uses one call to the phase oracle, plus a diffusion operation. Depending on convention, some descriptions may count additional oracle calls for state preparation, verification, or amplitude estimation, but the core Grover iteration uses one marking oracle query.

The parent document’s statement is therefore best read as a query-complexity claim: assuming access to an oracle that marks the \(M\) solutions among \(N\) candidates, Grover’s amplitude-amplification procedure needs on the order of \(\sqrt{N/M}\) oracle invocations to produce a solution with high probability.

Why More Solutions Mean Fewer Queries

The formula also has an intuitive interpretation. If there are more marked items, the initial uniform superposition already has more amplitude in the good subspace.

When \(M=1\), there is only one solution, and the query complexity becomes

\[ O(\sqrt{N}). \]

This is the familiar form of Grover’s search.

When \(M\) is larger, the expression decreases:

\[ O\left(\sqrt{\frac{N}{M}}\right). \]

For example, if \(M=N/100\), then one percent of the search space consists of solutions. The number of Grover iterations is on the order of

\[ \sqrt{\frac{N}{N/100}} = \sqrt{100} = 10. \]

This matches the geometric picture: if the good subspace is already large, the initial state is already closer to it, so fewer rotations are needed.

At the extreme, if \(M=N\), every candidate is a solution. Then no search is needed. The formula gives

\[ \sqrt{\frac{N}{N}}=1, \]

which is only a constant-order statement. In practice, one can measure immediately and obtain a solution. Big-\(O\) notation is coarse enough that it does not distinguish between zero iterations and a constant number of iterations.

Important Assumptions Behind the Expression

The expression rests on several assumptions that matter when verifying the statement in a research context.

First, it assumes an unstructured search problem. The oracle tells us whether a candidate is good, but it does not reveal additional exploitable structure. If the problem has algebraic or combinatorial structure, another algorithm may do better than Grover, or the oracle model may fail to capture the true cost.

Second, it assumes the algorithm starts in the uniform superposition over \(N\) candidates. More general amplitude amplification replaces \(M/N\) with the initial probability mass \(Z\) on good states. In that setting, the query count becomes

[ O\left(\frac{

τ TheoryTrace