---
title: Montanaro's Quantum Algorithmic Templates
url: https://www.emergentmind.com/topics/montanaro-s-algorithm
type: topic
---

# Montanaro's Quantum Algorithmic Templates

In the literature covered here, the expression “Montanaro’s algorithm” is used for several quantum algorithmic templates introduced by Ashley Montanaro, rather than for a single universally fixed procedure. The most prominent instances are “Quantum Search with Advice,” which studies average-case search under a known prior distribution over marked items; a quantum backtracking algorithm for constraint satisfaction problems, formulated as a quantum walk on a backtracking tree; and a quantum Monte Carlo method for mean estimation via amplitude estimation. Subsequent work extends these templates to promise-free span program and state-conversion settings, arbitrary trees with multiple marked vertices, space-efficient circuit implementations, heavy-tailed random variables, and non-uniform key guessing [2303.00217] [1711.05295] [1908.11291] [2401.07497] [2509.06549].

## 1. Search with advice and average-case query complexity

Montanaro’s “Quantum Search with Advice” addresses search problems in which the marked location is not assumed to be uniformly distributed. The setting is a list of \( n \) items together with a known probability distribution assigning a probability to each item being the marked one. The classical optimal strategy is to query items in order of decreasing probability, whereas the quantum strategy uses amplitude amplification in a way that non-uniformly samples or biases toward likelier locations. In this sense, the “advice” is additional information specifying the prior probabilities over positions containing the marked element [2303.00217].

The central performance notion is expected, or average-case, query complexity. For some advice distributions, especially power-law distributions, the average quantum advantage is much stronger than the worst-case quadratic improvement associated with unstructured Grover search. One summary in the supplied literature states that, with a power-law probability distribution on the location of the marked element, the expected quantum query complexity can be \( O(\log^{1/2} n) \) while the classical expected complexity is \( \Omega(n^{k+2}) \); the same source characterizes this as a super-exponential quantum speedup in average query complexity [2303.00217].

A later entropic analysis of the same non-uniform guessing paradigm makes the dependence on the prior distribution explicit. For ordered probabilities \( p_1 \geq p_2 \geq \ldots \), Montanaro’s expected quantum running time is
\[
T_Q = \sum_{i=1}^{|K|} \sqrt{i} \cdot p_i,
\]
and is tightly bounded by the Rényi entropy of order \( 2/3 \):
\[
\frac{2^{H_{2/3}(D)/2}}{\sqrt{1 + \log_2|K|}} \leq T_Q \leq 2^{H_{2/3}(D)/2}.
\]
The corresponding classical runtime is tightly bounded by \( 2^{H_{1/2}(D)} \), so for every non-uniform distribution \( D \), \( H_{2/3}(D) < H_{1/2}(D) \), yielding a super-quadratic quantum speed-up over classical key guessing [2509.06549].

## 2. Promise-free span programs, state conversion, and decision-tree generalizations

A major generalization places Montanaro’s advice-based phenomenon inside the span-program framework for quantum query complexity. Quantum span program algorithms for function evaluation can have reduced query complexity when the input is promised to have a certain structure, but the later contribution is a modified span program algorithm showing that these improvements persist even without a promise ahead of time. The same paper extends the method to the more general problem of state conversion and uses it to establish exponential and superpolynomial quantum advantages in average query complexity for several search problems [2303.00217].

For a span program \( P \) deciding a function \( f \), with positive and negative witness sizes \( w_+(P,x) \) and \( w_-(P,x) \), and with
\[
W_+ = \max_x w_+(P,x), \qquad W_- = \max_x w_-(P,x),
\]
the promise-free, input-adaptive query complexity is
\[
\min\left\{
O\left(\sqrt{w_+(P, x)W_-} \log\left(\frac{W_+}{w_+(P, x)\delta}\right)\right),
O\left(\sqrt{w_-(P, x)W_+} \log\left(\frac{W_-}{w_-(P, x)\delta}\right)\right)
\right\}.
\]
This matches the big-\( O \) dependence of the promised-case algorithm without requiring the promise to be known in advance. The mechanism uses interleaved one-sided tests for both \( f(x)=1 \) and \( f(x)=0 \), in growing query rounds, together with an explicit flag for completion [2303.00217].

The same framework yields average-case speedups for classical decision trees. For a function \( f \) with a classical decision tree \( T \), and with at most \( G \) hard (“red”) edges on any path, the quantum algorithm achieves average query complexity
\[
O\left( \sum_x p_x \sqrt{G \cdot |path(T, x)| \cdot \log^3 n} \right),
\]
or
\[
O\left( \sum_x p_x \sqrt{G \cdot |path(T, x)| \cdot \log n} \right)
\]
if verification is possible in \( O(1) \) queries. This turns the advice paradigm into a generic method for quantum speedups based on classical decision trees rather than only single-item search [2303.00217].

An explicit application is search for two marked items. For the problem of finding two \( 1 \)-valued bits in an \( n \)-bit string, the quantum average query complexity can be reduced to \( O(\log^{1/2} n) \) under a certain power-law distribution, while the classical average remains \( \Omega(n^{k+2}) \) for \( -2 < k < -3/2 \). The same work gives the expression
\[
O\left(\sum_{i=2}^n p(E_i^*) \sqrt{i \cdot 2 \log n}\right) = O(\log^{1/2} n),
\]
as a concrete instantiation of the average-case bound [2303.00217].

For state conversion, the extension states that for any converting vector set \( \mathscr{P} \),
\[
O\left(
\frac{\sqrt{w_+(\mathscr{P}, x) W_-}}{\varepsilon^{5}}
\log\left(\frac{W_+}{w_+(\mathscr{P}, x)\delta}\right)
\log\left(\frac{1}{\varepsilon}\right)
\right)
\]
is possible for average query complexity on input \( x \). A plausible implication is that Montanaro’s original insight about advice distributions was reinterpreted as a more general principle: quantum query algorithms can adapt to input easiness even when the relevant structure is not promised beforehand.

## 3. Quantum backtracking on search trees

A distinct use of the term refers to Montanaro’s quantum backtracking algorithm for constraint satisfaction problems. Here the search space of partial assignments explored by a classical backtracking algorithm is mapped to a tree in which each node is a partial assignment and each edge corresponds to assigning a new value to a variable. The quantum procedure performs a quantum walk on this tree, starting from the root. For each node \( x \), there is a diffusion operator \( D_x \); the walk uses the block-diagonal reflections
\[
R_A = \bigoplus_{x\in A} D_x,\qquad
R_B = |r\rangle\langle r| + \bigoplus_{x\in B} D_x,
\]
where \( A \) and \( B \) are the sets of nodes at even and odd distances from the root. Phase estimation on \( R_B R_A \) is used to detect whether the tree contains a solution [1908.11291].

In the form summarized in the implementation literature, if the backtracking tree has \( T \) vertices and depth \( n \), the algorithm finds a solution with complexity
\[
O\left(\sqrt{T}n^{3/2} \log n \log(1/\delta)\right),
\]
and if there is a unique solution this improves to
\[
O\left(\sqrt{T n} \log^3 n \log(1/\delta)\right).
\]
This is described as a quadratic quantum speedup over classical backtracking in terms of the number of nodes visited [1908.11291].

Subsequent work removes the restriction that there be a unique marked vertex and re-characterizes the performance in terms of effective resistance. In this formulation, a generalized algorithm handles arbitrary trees with an unknown number \( k \geq 1 \) of marked vertices. It uses amplitude estimation to determine a near-optimal weighting of a diffusion operator, prepares a superposition state that has support only on marked vertices and ancestors thereof, and then repeatedly samples this state while updating the input vertex. The resulting bounds are
\[
\widetilde{\mathcal{O}}\!\left(\sqrt{T R_{\mathrm{max}}}\right)
\]
for finding a single marked vertex,
\[
\widetilde{\mathcal{O}}\!\left(k\sqrt{T R_{\mathrm{max}}}\right)
\]
for finding all \( k \) marked vertices, and
\[
\widetilde{\mathcal{O}}\!\left(\sqrt{T \overline{\eta}}\right)
\]
for existence detection, where \( R_{\mathrm{max}} \) is the maximum effective resistance encountered by the algorithm and \( \overline{\eta} \) is the effective resistance from the root to the marked set [1711.05295].

This effective-resistance perspective is structurally important because it makes the runtime depend on how accessible the marked set is from the root. The same source states that
\[
R_{\mathrm{max}} \in \left[\max\left(1/k, 1/d_r\right),\, n\right],
\]
with \( d_r \) the root degree and \( n \) the tree depth. If there are no marked vertices, the effective resistance becomes infinite and the scaling returns to Montanaro’s original existence bound, namely \( \widetilde{\mathcal{O}}(\sqrt{Tn}) \) [1711.05295].

## 4. Space-efficient implementations for CSPs, graph coloring, and SAT

The backtracking algorithm was later developed into a practical, space-efficient implementation. Under the assumptions that a CSP has \( m \) constraints on \( n \) variables and that the union of the domains in which these variables take their value is of cardinality \( d \), the implementation can be done using \( O(n \log d) \) data qubits. The predicate associated to the CSP can be implemented with an additional register of \( O(\log m) \) qubits [1908.11291].

The representation of partial assignments uses \( n\lceil \log(d+1)\rceil = O(n\log d) \) qubits, with each variable encoded in \( \lceil\log(d+1)\rceil \) qubits to accommodate \( d \) possible values plus a symbol \( \ast \) for “unassigned.” Predicate evaluation is handled by a quantum counter register of size \( \lceil\log(m+1)\rceil = O(\log m) \): for each violated constraint, the counter is incremented, and the counter is \( 0 \) if and only if all constraints are satisfied. This replaces the more expensive use of \( m+1 \) work qubits [1908.11291].

The paper gives explicit implementations for graph coloring and SAT. In graph coloring, each vertex variable takes values in \( \{1,\ldots,d\} \) plus \( \ast \), and the constraints are that variables are assigned and adjacent vertices have different colors. In SAT, Boolean variables are encoded as \( |10\rangle \), \( |11\rangle \), and \( |00\rangle \) for \( 0 \), \( 1 \), and \( \ast \), enabling efficient checking and negation or disjunction. The same work provides explicit circuit sketches for checking assignment status, enforcing coloring constraints, and implementing the overall reflections \( R_A \) and \( R_B \) [1908.11291].

A substantial practical issue is variable ordering. Dynamic variable ordering heuristics require \( O(n\log n) \) extra qubits and more complex circuitry, whereas static variable ordering can be precomputed classically and hardwired into the circuit. The tradeoff is summarized by the condition
\[
\frac{c_T}{c_{T'}} \ge 1 + \frac{d_h}{d_R},
\]
where \( c_T \) and \( c_{T'} \) denote the number of quantum walk steps for static and dynamic heuristics, \( d_R \) is operator depth without the heuristic, and \( d_h \) is the heuristic circuit depth. The practical conclusion reported in the supplied material is that static variable ordering is preferred for qubit-efficiency, and that MD (max degree) is empirically the best static heuristic for random graphs of size \( n=10\text{--}20 \) and \( d=3\text{--}6 \) [1908.11291].

## 5. Quantum Monte Carlo mean estimation and heavy-tailed extensions

Another use of the label refers to Montanaro’s quantum Monte Carlo method for estimating the expectation of a random variable \( X \) given oracle access to sampling. In its original form, the method assumes finite variance and estimates \( \mathbb{E}[X] \) with additive error \( \epsilon \). The classical sample complexity is \( O(\sigma^2/\epsilon^2) \), while the quantum sample complexity is reduced quadratically to \( O(\sigma/\epsilon) \). The method builds on amplitude estimation and quantum phase estimation [2401.07497].

A 2024 extension addresses the regime of infinite variance, assuming only that \( X \) has a finite \( (1+\delta) \)-th moment for \( 0 < \delta < 1 \):
\[
\mathbb{E}[|X|^{1+\delta}] = C_{1+\delta} < \infty.
\]
The algorithm truncates the variable at a threshold depending on \( C_{1+\delta} \) and \( \epsilon \), so that the truncated variable has finite variance, and then applies quantum mean estimation. With an upper bound \( C \) on \( \mathbb{E}[|X|^{1+\delta}] \), the algorithm outputs an estimator \( \hat{\mu} \) satisfying
\[
|\hat{\mu} - \mathbb{E}[X]| \le \epsilon
\]
with probability at least \( 4/5 \), using
\[
O\left( C^{1/(2\delta)} \epsilon^{-(1+\delta)/(2\delta)} \right)
\]
applications of the quantum sampling oracle [2401.07497].

The truncation threshold is stated as
\[
y = (8C/\epsilon)^{1/\delta},
\]
which ensures that the tail contribution is at most \( \epsilon/8 \). The corresponding classical sample complexity under the same moment assumption is
\[
O\left( C^{1/\delta} \epsilon^{-(1+\delta)/\delta} \right),
\]
so the quantum speedup remains quadratic in both \( C \) and \( \epsilon \). Matching lower bounds are also given:
\[
\Omega\left( C^{1/\delta} \epsilon^{-(1+\delta)/\delta} \right)
\]
classically and
\[
\Omega\left( C^{1/(2\delta)} \epsilon^{-(1+\delta)/(2\delta)} \right)
\]
quantumly [2401.07497].

The same work emphasizes that its contribution is not the creation of a new algorithmic primitive but the analysis of existing quantum mean-estimation methods under additional information about the random variable. It also describes a hierarchy of supplementary information, ranging from an upper bound on the \( (1+\delta) \)-th moment, to an upper bound on the central \( (1+\delta) \)-th moment, to an upper bound on variance, and finally to full histogram or tail information [2401.07497].

## 6. Conceptual scope, common confusions, and later reinterpretations

A recurrent source of ambiguity is terminological. In the supplied literature, “Montanaro’s algorithm” does not denote one procedure with one oracle model, but rather a family of algorithmic constructions whose common ingredients include amplitude amplification, phase estimation, amplitude estimation, and adaptivity to non-uniform structure. This suggests that the unifying theme is not a single circuit identity, but a methodological pattern: exploit prior structure—advice distributions, witness sizes, effective resistance, or moment bounds—to reduce average or instance-dependent complexity.

Several distinctions are therefore essential. In “Search with Advice,” advice is a prior distribution over locations of a marked item, not a promise that the input belongs to an easier subclass. In the span-program generalization, the principal innovation is precisely the removal of the need for such a promise ahead of time, while preserving the improved dependence on witness size [2303.00217]. In quantum backtracking, the improvement is tied to the geometry of the search tree and later to effective resistance, rather than to a prior distribution on answers [1711.05295]. In quantum Monte Carlo, the decisive side information is a moment bound on the sampled random variable, not an advice distribution over discrete search positions [2401.07497].

The later entropy-based treatment of key guessing further clarifies the advice-search perspective. For product distributions \( D=\chi^n \), the single-key cost is governed by Rényi entropies,
\[
T_C \approx 2^{H_{1/2}(D)},\qquad
T_Q \approx 2^{H_{2/3}(D)/2},
\]
whereas in the multi-key setting, when a constant fraction of keys is to be guessed, the cost per key becomes \( 2^{H(D)} \) classically and \( 2^{H(D)/2} \) quantumly, with \( H(D) < H_{2/3}(D) < H_{1/2}(D) \) for non-uniform distributions [2509.06549]. This sharpens a common misconception: the “quadratic speedup” slogan is exact for uniform search, but non-uniform advice can yield super-quadratic, and in some average-query formulations superpolynomial or super-exponential, separations.

Taken together, these developments place Montanaro’s contributions at the intersection of average-case quantum algorithms, query complexity, quantum walks, and amplitude-estimation-based inference. Later papers do not simply reapply a fixed original algorithm; they reframe its underlying principle in different formal languages—decision trees, span programs, effective resistance, and moment hierarchies—and thereby broaden the range of problems for which structured quantum speedups can be proved [2303.00217] [1711.05295] [2401.07497] [2509.06549].

Source: https://www.emergentmind.com/topics/montanaro-s-algorithm