Level 7 · Capstone Topics

Quantum Algorithm Design Patterns

About 5,083 words · roughly 23 minute read · sources checked December 2, 2026

Quantum algorithms look like a long list of unrelated tricks: Deutsch–Jozsa, Grover, Shor, VQE. Underneath, they are assembled from a small set of reusable patterns. Once you can recognise the patterns, a new algorithm stops being a surprise and becomes a combination you can read.

This lesson names the main patterns and gives each a small numerical example that you can check by hand or with a few lines of numpy. All the numbers below were computed by me with numpy. We cover parallel evaluation and interference, phase kickback, amplitude amplification, phase estimation, Fourier sampling, variational loops and Hamiltonian simulation, and end with a table that matches problem structure to a pattern.

You should know the gates and circuits from the earlier levels. The Grover, Shor and simulation lessons show full algorithms; here we look at the parts they share.

What you will learn

  • How a Hadamard sandwich turns a hidden property of a function into a measurable probability, with Deutsch–Jozsa as the worked case.
  • How phase kickback moves a function value into a phase.
  • How amplitude amplification works, why it costs about 1/√a rounds, and why doing too many rounds hurts.
  • How phase estimation reads out a phase with t bits, and how likely each outcome is.
  • How a variational loop uses parameter-shift gradients, with a one-qubit example.
  • Which pattern fits which kind of problem.

Helpful first: Quantum Algorithms, Grover’s Algorithm, Reading a Quantum Circuit Diagram.

Why patterns

A quantum computer cannot read out its whole state. A measurement returns one outcome, so an algorithm must arrange the state so that the outcome you want has a high probability. Nearly every known algorithm does this with the same few moves: prepare a superposition, apply an operation that encodes the problem, and use interference so the useful answer is likely and the others cancel.

The paper “Quantum Algorithms Revisited” by Cleve, Ekert, Macchiavello and Mosca makes this point directly. Its abstract describes quantum computation as multi-particle interference, says this reveals a common pattern behind many algorithms, and shows how existing algorithms relate to different instances of quantum phase estimation. That is the view this lesson follows.

PatternWhat it doesWhere you meet it
Superposition + oracleEvaluates a function on all inputs at once, in one stateDeutsch–Jozsa, Grover, Shor
Phase kickbackMoves a function value into a phase on the input registerAlmost every oracle-based algorithm
Interference (Hadamard sandwich)Makes wanted outcomes add and unwanted ones cancelDeutsch–Jozsa, Bernstein–Vazirani, Simon
Amplitude amplificationBoosts the probability of a good outcomeGrover, quantum counting
Phase estimationReads an eigenvalue phase into binary digitsShor, quantum chemistry, counting
Fourier samplingReveals hidden periodic structureShor, Simon
Variational loopTunes circuit parameters with a classical optimiserVQE, QAOA
Hamiltonian simulationImplements time evolution of a quantum systemChemistry, materials

The patterns in this lesson. The last column is a summary of standard usage.

Pattern 1: superposition and an oracle

Apply Hadamard gates to n qubits that start in |0…0⟩ and you get an equal superposition of all N = 2ⁿ basis states. A function f(x) is given to the circuit as an oracle, a gate U_f that acts as U_f |x⟩|y⟩ = |x⟩|y ⊕ f(x)⟩. Sending the superposition through it applies f to every input in a single use of the oracle.

This is where the popular phrase “quantum computers try every answer at once” comes from, and it is misleading. The result is one entangled state holding all the values of f, and a measurement gives only one of them at random. The real work comes in the next patterns, which arrange for the information you want to appear in the measurement statistics.

Parallel evaluation is not parallel readout

After one oracle call the state contains f(x) for all x, but you can read out only about one number’s worth of information. If you stop here you learn nothing more than one random evaluation.

Pattern 2: phase kickback

Phase kickback is the trick that turns an oracle that writes f(x) into a register into one that multiplies the state by (−1)^f(x). Put the output qubit in the state |−⟩ = (|0⟩ − |1⟩)/√2 before the oracle.

  1. The oracle maps |x⟩|y⟩ to |x⟩|y ⊕ f(x)⟩.
  2. If f(x) = 0 then |−⟩ is unchanged.
  3. If f(x) = 1 then the oracle swaps the two terms of |−⟩, so it becomes (|1⟩ − |0⟩)/√2 = −|−⟩.
  4. Either way, |x⟩|−⟩ maps to (−1)^f(x) |x⟩|−⟩. The output qubit is left in |−⟩, unentangled, and the information has moved into a phase on the input register.

The reading-a-circuit lesson showed a controlled operation acting on a qubit in a superposition and the phase moving to the control side. That is the same effect. Phase is invisible if you measure in the computational basis, which is why this pattern is always followed by interference.

|x>|->  --U_f-->  (-1)^f(x) |x>|->
sum over x:  (1/sqrt N) sum_x (-1)^f(x) |x>
Phase kickback. The function values now sit in the signs of the amplitudes.

Pattern 3: interference and the Hadamard sandwich

After kickback, the input register holds (1/√N) Σ (−1)^f(x) |x⟩. Applying Hadamards to all n qubits again turns this into a state whose amplitude on |0…0⟩ is (1/N) Σ (−1)^f(x), the average of the signs. This H – oracle – H structure is the Hadamard sandwich.

The amplitude on |0…0⟩ is a plain average, so you can read off what the function does by looking at its probability, which is the square of that average. This is the whole of the Deutsch–Jozsa algorithm.

Worked example

Deutsch–Jozsa on 3 qubits (N = 8)

  1. The problem is promised to be one of two kinds: f is constant, or f is balanced (equal to 1 on exactly half of the inputs). A classical deterministic algorithm may need 2ⁿ⁻¹ + 1 = 5 queries to be sure when n = 3. This is the standard result and I did not look it up. The quantum circuit uses one.
  2. Constant f = 0: all eight signs are +1, the average is 1, and P(000) = 1.
  3. Balanced f = parity of the bits of x: four signs +1 and four −1, the average is 0, and P(000) = 0.
  4. So measuring 000 means constant, and any other result means balanced. One oracle call decides.
  5. The promise matters. Take f = 1 on x ∈ {0, 1, 2} and 0 on the other five. This f is neither constant nor balanced. The signs sum to 5 − 3 = 2, the average is 0.25, and P(000) = 0.0625. The circuit returns 000 about 6% of the time, and you cannot read a verdict from it.
Function (n = 3)Sum of signsAmplitude on 000P(000)
constant 0811
parity of x000
f = 1 on x ∈ {0, 1, 2}20.250.0625

Deutsch–Jozsa outcomes, computed with numpy.

Be honest about the speed-up

Deutsch–Jozsa shows a quantum advantage in query count for a contrived promise problem. A randomised classical algorithm solves it with high probability using very few queries, so it is a teaching example and not a practical speed-up. That randomised point is background knowledge, not something I verified here.

A second sandwich: Bernstein–Vazirani

The same circuit solves a slightly different problem. Suppose f(x) = s · x (the parity of the bits of x that are 1 in a hidden string s), and you must find s. Classically each query gives one bit of information, so n queries are needed. This count is standard background that I did not look up.

With the Hadamard sandwich the amplitude on outcome y is (1/N) Σ (−1)^(s·x + y·x). This sum is 1 when y = s and 0 for every other y, because the signs cancel exactly. One query returns s with certainty.

Worked example

n = 4, hidden string s = 1011

  1. Computing all 16 amplitudes numerically, the outcome y = 1011 (decimal 11) has amplitude 1.0 and the other 15 outcomes have amplitude 0.
  2. So a single run, measured, returns 1011 every time. A classical algorithm needs four queries, one for each bit, for example by asking f(1000), f(0100), f(0010) and f(0001).
  3. The gap is n queries against 1, which is a modest advantage and again in the query-count model. It shows the pattern clearly, because every wrong answer is cancelled and the right one is the only one left.

Same sandwich, different question

Deutsch–Jozsa and Bernstein–Vazirani use the identical circuit. Only the promise about f changes, and with it the way you read the final distribution.

Pattern 4: amplitude amplification

Suppose a circuit produces a “good” outcome with probability a. Repeating it and checking each result takes about 1/a tries on average. The paper by Brassard, Høyer, Mosca and Tapp shows that amplitude amplification finds a good element using about 1/√a applications of the algorithm and its inverse, a quadratic improvement, and that it generalises Grover’s search beyond an equal superposition and a single good item. The abstract also notes that this holds when the algorithm makes no intermediate measurements.

Geometrically, write sin θ = √a. The state is a vector at angle θ from the “bad” direction in a two-dimensional plane. Each round (one reflection about the good states, one about the starting state) turns it by 2θ. After k rounds the good probability is sin²((2k+1)θ).

chance of success, starting from a = 0.12 rounds: 0.999k = 4 overshoots01234567891011rounds of amplification k
Good-outcome probability after k rounds for a = 0.1. It peaks at k = 2, then falls.

Worked example

a = 0.1, so θ = arcsin √0.1 = 0.3218

  1. Probability after k = 0, 1, 2, 3, 4, 5, 6, 7 rounds: 0.100, 0.676, 0.999, 0.603, 0.059, 0.150, 0.745, 0.987.
  2. The best choice is k = 2, giving 0.999. A classical repeat-and-check needs about 1/a = 10 tries for success.
  3. Each round uses the circuit and its inverse once, so the cost grows in proportion to k, and the total scales as about 1/√a.

More rounds is not better

Amplitude amplification rotates a vector, and keeps rotating. At k = 4 the probability has fallen to 0.059, below where it started. You must stop at the right round. If a is unknown, the paper’s abstract says the method still works, using strategies that try different round counts.

aBest kP at best kClassical tries ≈ 1/a(π/4)/√a
0.120.9990102.5
0.0170.99531007.9
0.001240.99961,00024.8
0.0001781.000010,00078.5

Best round counts, computed with numpy. The last column is the approximation (π/4)/√a.

The table shows the scaling plainly. Each factor of 10 in 1/a costs about a factor of √10 ≈ 3.2 more rounds. This is the same quadratic speed-up as Grover’s algorithm, which is the case a = 1/N. It is a speed-up of the square root, not an exponential one, and each round also needs a circuit that can be run and inverted.

Amplification at search scale

Grover search is amplitude amplification with a = 1/N for one marked item among N. The best number of rounds is about (π/4)√N, against an average of N/2 classical checks.

NQuantum rounds ≈ (π/4)√NClassical average ≈ N/2
1,024 (2¹⁰)25512
1,048,576 (2²⁰)804524,288
1,073,741,824 (2³⁰)25,736536,870,912

Grover scaling, computed with numpy.

For N = 2²⁰ the optimal 804 rounds give a success probability of 0.9999998. The saving is large in the count of oracle calls, but each call is a full circuit that must be run on a fault-tolerant machine, so the comparison with a classical computer that checks items at gigahertz speed depends on the clock rates and error-correction overhead. The path-to-fault-tolerance lesson shows why that overhead is large.

Pattern 5: phase estimation

Many problems reduce to finding the phase φ in U|ψ⟩ = e^(2πiφ)|ψ⟩, where U is a unitary you can apply and |ψ⟩ is an eigenstate. Phase estimation uses t counting qubits, applies controlled-U^(2^j) for j = 0 to t − 1, then an inverse quantum Fourier transform. The counting register then holds an integer m with φ ≈ m/2ᵗ.

The counting register’s amplitudes follow a pattern you can compute directly. The probability of outcome m is the squared size of the Fourier sum of e^(2πiφj) over j, normalised by 2ᵗ.

Worked example

t = 4 counting qubits (16 outcomes)

  1. If φ = 5/16 exactly, the outcome is 5 with probability 1.
  2. If φ = 0.3, the exact value 0.3 × 16 = 4.8 lies between outcomes 4 and 5. Outcome 5 has probability 0.876, outcome 4 has 0.055, and outcome 6 has 0.025. The other outcomes share the remaining 0.044.
  3. Reading m = 5 gives φ ≈ 5/16 = 0.3125, an error of 0.0125.
Counting qubits tGrid spacing 1/2ᵗP(nearest outcome), φ = 0.3
30.1250.578
40.06250.876
60.01560.875
80.00390.875

Phase estimation of φ = 0.3, computed with numpy.

More counting qubits make the estimate finer, but the chance of landing on the nearest grid point stays near 0.875 for this φ, because the fractional position of 0.3 on the grid stays the same. The cost of finer precision is exponential: the controlled-U^(2^j) with the largest power uses U applied 2ᵗ⁻¹ times, so one extra bit doubles the largest block. Precision of ε in φ takes roughly 1/ε applications of U.

If you want a guarantee, ask for the two nearest outcomes. For φ = 1/3 the probability of landing on one of the two closest grid points is 0.857 for t = 4, 0.855 for t = 6 and 0.855 for t = 8. Adding extra qubits and discarding them raises the success probability further, which is standard practice and I did not verify it here.

Phase estimation is the common parent

Shor’s algorithm is phase estimation applied to modular multiplication, Cleve et al. describe many algorithms as instances of it, and the quantum counting method in the amplitude-estimation paper combines it with Grover iterations. The abstract of that paper says amplitude estimation combines ideas from Grover’s and Shor’s algorithms.

Pattern 6: Fourier sampling

If a function repeats with period r, the quantum Fourier transform turns that periodic structure into peaks at multiples of N/r. Measuring gives a multiple of N/r with high probability, and number theory recovers r. This is the core of Shor’s algorithm, covered in its own lesson.

Worked example

A clean case: N = 16 and period r = 4

  1. A state that is equal on x = 0, 4, 8, 12 and zero elsewhere has Fourier peaks at multiples of N/r = 4.
  2. The outcomes 0, 4, 8, 12 each have probability 1/4, and all other outcomes have probability 0.
  3. From the outcome 4, 16/4 = 4 gives the period. From outcome 0 you learn nothing, which is why the procedure is repeated.
  4. When r does not divide N, the peaks spread slightly. The continued-fraction step in the Shor lesson handles that.

Pattern 7: variational loops

Near-term machines are noisy and shallow, so a different pattern keeps the quantum circuit short. A parameterised circuit prepares a state |ψ(θ)⟩, the device measures the energy or cost E(θ), and a classical optimiser adjusts θ. This hybrid loop underlies VQE and QAOA.

A one-qubit example shows the whole mechanism. Let the energy be E(θ) = cos θ + 0.5 sin θ, which is what you would measure for a Hamiltonian H = Z + 0.5 X with the state cos(θ/2)|0⟩ + sin(θ/2)|1⟩. The exact minimum is −√(1 + 0.25) = −1.118.

Worked example

Gradient descent with the parameter-shift rule

  1. For gates of this form, the gradient can be computed from two extra circuit runs: dE/dθ = [E(θ + π/2) − E(θ − π/2)] / 2. This rule is standard background and I did not look it up here, but you can confirm it for this E by differentiating.
  2. Start at θ = 0, where E = 1. The gradient is [0.5 − (−0.5)]/2 = 0.5. With learning rate 0.4, the new θ is −0.2.
  3. Energy after steps 1 to 10: 0.881, 0.660, 0.299, −0.178, −0.633, −0.923, −1.051, −1.097, −1.112, −1.116.
  4. After ten steps the energy is within 0.002 of the exact minimum −1.118.

On real hardware each energy value is estimated from shots, so each gradient has statistical noise of order 1/√shots, as the measurement lessons computed. The loop works with noisy gradients, but needs many shots and careful step sizes.

What can go wrong

Optimisers can get stuck in local minima, and for large circuits the gradients can become extremely small (often called barren plateaus). These are widely discussed problems that I mention as background, not as results I checked.

Pattern 8: Hamiltonian simulation

Simulating a quantum system’s time evolution e^(−iHt) is the oldest motivation for quantum computers and the basis of chemistry and materials applications. The usual approach splits H into pieces you can implement and alternates between them in small steps, the Trotter method. The simulation lesson works through the errors and costs with numbers. Here the point is the pattern: simulation provides the unitary, and phase estimation reads out energies from it.

Trotter error in numbers

To see the simulation pattern concretely, take one qubit with H = X + Z and evolve |0⟩ for time t = 1. The exact evolution is e^(−iHt). The Trotter approximation replaces it by r repetitions of e^(−iX/r) followed by e^(−iZ/r), because X and Z do not commute and cannot be exponentiated separately without error.

Steps rInfidelity 1 − |⟨exact|approx⟩|²Operator-norm error
10.4060.799
20.07940.362
40.01750.176
80.004130.0875
160.001000.0437
320.0002470.0218

First-order Trotter error for H = X + Z at t = 1, computed with numpy.

Each doubling of r halves the operator error and cuts the infidelity about fourfold, matching the standard picture that the first-order error shrinks like 1/r. The price is circuit depth: r steps use r times as many gates. For a large system the same trade-off decides how many gates a simulation needs, which is why the simulation lesson spends time on higher-order formulas.

Reading three algorithms with the four questions

Here is the four-question method applied to three algorithms from this course. The point is to practise recognising structure, not to repeat the full algorithms.

QuestionGroverShor (period finding)VQE
What is in superposition?All N inputs, equallyAll values of x in the counting registerNothing special: a parameterised state |ψ(θ)⟩
What does the oracle or unitary encode?A phase flip on the marked itemModular exponentiation a^x mod NThe ansatz circuit; the Hamiltonian is measured
Where does interference happen?In each reflection about the averageIn the inverse Fourier transformInside the ansatz; the output is an expectation value
What is measured?The register, expecting the marked itemThe counting register, giving a multiple of N/rPauli terms of H, many shots each
Which pattern?Amplitude amplificationPhase estimation and Fourier samplingVariational loop
Typical gainQuadraticSuperpolynomial over the best known classical factoring methodsNone proven

The same four questions applied to three algorithms. The gain row is a summary of the standard picture from the earlier lessons.

A cost model: counting qubits

Another useful habit is counting the resources each pattern needs. These counts follow from the circuits described above.

PatternQubitsOracle or unitary uses
Deutsch–Jozsa / Bernstein–Vazirani, n-bit inputn + 1 (one helper in |−⟩)1
Amplitude amplification with aQubits of the base circuitAbout (π/4)/√a rounds
Phase estimation with t bitst counting qubits plus the qubits of UAbout 2ᵗ − 1 applications of U in total
Variational loopQubits of the ansatzMany circuit runs: shots × parameters × iterations

Rough resource counts. For phase estimation, 1 + 2 + … + 2ᵗ⁻¹ = 2ᵗ − 1 applications of U.

The phase estimation count is worth checking: with t = 4, the blocks use U, U², U⁴ and U⁸, which is 1 + 2 + 4 + 8 = 15 = 2⁴ − 1 applications. For 10 bits of precision that is 1,023 applications. This is why precision is the main cost driver and why error rates matter so much for the long circuits.

Worked example

Variational loop cost

  1. Suppose a circuit has 20 parameters, each gradient entry needs two shifted circuits, and each circuit is run 1,000 times.
  2. One gradient costs 20 × 2 × 1,000 = 40,000 shots. One hundred iterations cost 4,000,000 shots.
  3. At 1,000 shots per second this is about 4,000 seconds, a little over an hour, before counting queueing or error mitigation. The numbers are illustrative, not measured on a real device.

Choosing a pattern

If your problem looks like…Think about…Typical gain
Decide a global property of a function with a promiseHadamard sandwich with kickbackFew queries; mostly educational
Find an item among many with a checkable testAmplitude amplificationQuadratic: about √ of the classical tries
Hidden period or group structureFourier sampling plus classical post-processingExponential in specific cases such as factoring
Find an eigenvalue of a unitaryPhase estimationPrecision ε costs about 1/ε uses of U
Ground-state energy on a small noisy deviceVariational loopNo proven advantage; heuristic
Dynamics of a quantum systemHamiltonian simulationBelieved large, depends on system and precision
Count the solutionsAmplitude estimation (amplification + phase estimation)Quadratic over classical sampling

A pattern selector. The gains column is my summary of the standard picture, and the “believed” entries are not proven.

Reading an algorithm usually means answering four questions. What is in superposition? What does the oracle or unitary encode? Where does the interference happen? And what is measured at the end? Try this on Grover (amplification), Shor (period finding with phase estimation) and VQE (a variational loop), and the structure becomes visible.

An experiment: how fast does Trotter error shrink?

The simulation pattern replaces the evolution under a sum of non-commuting terms with a product of evolutions under each term. The accuracy depends on how many small steps you take and on the order of the product formula. Rather than quote the textbook scaling, I measured it. I wrote a NumPy experiment on a two-qubit Hamiltonian made of three non-commuting terms: H = 0.7 X⊗X + 0.5 Z⊗I + 0.3 I⊗Z, evolved for total time t = 1. The reference is the exact matrix exponential. For each number of steps r, I built the first-order (Lie–Trotter) product and the second-order symmetric (Strang) product and measured the operator-norm distance to the exact evolution.

Steps rFirst-order errorSecond-order error
10.49360.1475
20.23440.0349
40.11560.00860
80.05760.00214
160.02880.000535
320.01440.000134
640.007190.0000334

Operator-norm error of product formulas for H = 0.7 X⊗X + 0.5 Z⊗I + 0.3 I⊗Z at t = 1. My own NumPy experiment.

The pattern in the columns is the whole story. Doubling the number of steps halves the first-order error, because the error falls like 1/r. It quarters the second-order error, because that falls like 1/r². In the table, going from 8 to 16 steps takes the first-order error from 0.0576 to 0.0288 (a factor of 2.0) and the second-order error from 0.00214 to 0.000535 (a factor of 4.0).

What it costs to reach a target accuracy

Suppose you want an error of 0.001. Fitting the table gives first-order error ≈ 0.4936/r and second-order error ≈ 0.1475/r². Solving for r:

first order:  r ≈ 0.4936 / 0.001 ≈ 494 steps, each with 3 exponentials: about 1,480 exponentials
second order: r ≈ √(0.1475 / 0.001) ≈ 12.1, so 13 steps, about 4 exponentials per step after merging neighbours: about 52 exponentials
My own estimate from the fitted scalings. The merge assumes that the half-steps at the ends of neighbouring steps combine into one, a standard compiler trick.

That is a saving of roughly thirty times in the number of exponentials for the same accuracy, on this tiny example. The saving grows as the target error shrinks, because the exponents differ. Higher-order formulas exist and have still better scaling, at the price of more complicated step structure, which is why the choice of formula is a real design decision and not a detail.

Why this matters for hardware

Every exponential becomes several gates, and the circuit depth sets how much noise you accumulate. A better product formula is as valuable as a better qubit, because it lets you reach a given accuracy with a shallower circuit. This is the same trade-off that appears in the Grover noise study elsewhere on this site: do the least work that gets the answer.

The shot budget behind the variational pattern

The variational pattern does not read out a state. It estimates a number, such as an energy, by averaging many measurements. The accuracy of an average of N independent shots is about σ/√N, where σ is the standard deviation of a single shot. To reach accuracy ε you therefore need about (σ/ε)² shots, and that is expensive when ε is small.

Target accuracy εShots needed if σ = 1Shots needed if σ = 0.1
0.11001
0.0110,000100
0.0016390,6253,906
0.0011,000,00010,000

Shots needed to reach accuracy ε: N ≈ (σ/ε)². My own arithmetic; σ is the standard deviation of a single-shot result for the measured quantity, in the same units as ε.

The value 0.0016 appears because chemistry often quotes chemical accuracy as about 1.6 milliHartree, roughly one kilocalorie per mole. That figure is from my general knowledge of the field and I did not open a source for it here. A molecular Hamiltonian is a sum of many Pauli terms, and each group of terms needs its own measurements, so the totals multiply by the number of groups. A hundred groups at 390,625 shots each is 39 million shots for a single energy evaluation, and an optimiser needs hundreds of evaluations.

This arithmetic explains two things that surprise newcomers. First, why variational algorithms run for hours or days on cloud hardware even for small molecules. Second, why researchers work on reducing the variance σ, by grouping commuting terms, by choosing better measurement bases, or by classical shadows, which are covered in our dictionary.

The quadratic cost of precision

Ten times more accuracy costs a hundred times more shots. That is the same square-root law as for any polling or sampling, and it is why a quantum method that reads out its answer by sampling carries a built-in cost that phase estimation, which reads digits directly, does not.

A one-page summary of the patterns

Putting the patterns side by side makes their trade-offs clear. The last column is my own qualitative judgement from the lessons on this site.

PatternMain resourceTypical gainNeeds error correction?
Oracle with phase kickbackOne or a few oracle callsQuery savings in promise problemsNo, for small instances
Interference (Hadamard sandwich)Shallow circuitsTurns phases into bitsNo
Amplitude amplificationAbout √(N/M) oracle iterationsQuadraticPractically yes at large N
Phase estimation and QFT2^t controlled-U applications for t bitsSuperpolynomial in some usesYes
Variational loopMillions of shots, shallow circuitsUnprovenNo, but noise limits accuracy
Product-formula simulationSteps × terms exponentialsExponential memory savings, in principleYes for useful sizes

Six algorithm design patterns and what each costs.

The table shows a divide that organises the whole field. Patterns in the upper rows run on today's noisy devices, but their gains are limited or unproven. Patterns in the lower half promise much larger gains but need the error-corrected machines that are still being built. The roadmaps of hardware companies are, in effect, plans to move from the first group to the second.

Anti-patterns to avoid

  • Choosing a pattern because it sounds quantum, without checking the classical alternative.
  • Counting qubits and ignoring depth. A circuit that fits in 20 qubits but needs a million gates is out of reach.
  • Ignoring the cost of the oracle. In most real problems building the oracle is the hard part.
  • Quoting a speed-up without the comparison class: deterministic classical, randomised classical or best-known classical.
  • Loading data as if it were free. Preparing a state from classical data can cost as much as the saved computation.

These are the same questions a reviewer would ask of any claimed quantum advantage, and asking them of your own design is the quickest way to find its weak point before the hardware does.

Worked example: choosing a pattern for a real question

Suppose a colleague asks whether a quantum computer could help find which of one million configurations of a production schedule has the lowest cost. Run the questions from this lesson in order. First, is there structure? A schedule cost has no promise like 'balanced or constant', so the Deutsch–Jozsa pattern does not apply. Second, is there a checkable property? Yes: given a schedule you can compute its cost, so an oracle that marks 'cost below a threshold' can be built. That points to amplitude amplification.

Third, what is the gain? For N = 1,048,576 configurations and one good answer, about 804 iterations against roughly 524,288 classical checks (see the Grover lesson table). Fourth, what is the catch? Each iteration must evaluate the whole cost function reversibly, and the machine must be error-corrected to run 804 iterations of a deep oracle. Fifth, the classical alternative: a good classical heuristic or an integer-programming solver often finds a near-optimal schedule without checking all configurations at all, so the real comparison is not against brute force.

The honest conclusion is: the pattern fits, the quadratic gain is real in principle, but today it does not beat strong classical solvers, and it needs hardware that does not yet exist at that scale. Writing that paragraph is the practical skill this lesson is meant to build. It is also the most useful thing a quantum-literate engineer can say in a meeting full of enthusiasm.

Common mistakes

MistakeCorrection
“It evaluates every input, so it reads every output”One measurement returns one outcome. Interference must concentrate the answer.
“More Grover rounds always help”The probability oscillates. For a = 0.1 it is 0.999 at k = 2 and 0.059 at k = 4.
“Quantum search is exponentially faster”It is quadratically faster, about 1/√a against 1/a.
“Phase estimation is free precision”Each extra bit doubles the largest controlled block.
“Variational circuits are proven faster”They are heuristics. No general advantage is established.
Ignoring the promise in Deutsch–JozsaOutside the promise, P(000) = 0.0625 in the example and means nothing.

Common mistakes with algorithm patterns.

Practice problems

Check yourself

For Deutsch–Jozsa with n = 3 and f(x) = 1 for all x, what is P(000)?

All signs are −1, the average is −1, and P = 1. This f is constant.

For n = 2 (N = 4) with f(x) = 1 only for x = 3, what is P(00)?

Signs sum to 3 − 1 = 2, the average is 0.5, so P = 0.25. It is neither constant nor balanced.

Why does phase kickback need the target qubit in |−⟩?

Because XOR with 1 swaps the terms of |−⟩, which only multiplies it by −1. A |0⟩ target would become entangled instead.

Compute θ for a = 0.04, and the best number of rounds.

θ = arcsin 0.2 = 0.2014. Best k satisfies (2k+1)θ ≈ π/2, so k ≈ 3.4, so k = 3. P = sin²(7 × 0.2014) = 0.974.

With a = 0.1, what is the probability after 3 rounds?

sin²(7 × 0.3218) = 0.603.

With 3 counting qubits, how many outcomes are there and what is the spacing?

8 outcomes, spacing 1/8 = 0.125.

Phase estimation returns m = 3 with t = 4. What is the estimate of φ?

3/16 = 0.1875.

Compute the energy for E(θ) = cos θ + 0.5 sin θ at θ = π/2.

0 + 0.5 = 0.5.

Why is the parameter-shift gradient at θ = 0 equal to 0.5?

[E(π/2) − E(−π/2)]/2 = [0.5 − (−0.5)]/2 = 0.5. It matches dE/dθ = −sin θ + 0.5 cos θ = 0.5.

Name the pattern behind each: Grover, Shor, VQE.

Amplitude amplification, Fourier sampling with phase estimation, a variational loop.

References and further reading

I opened the arXiv abstract pages for Brassard, Høyer, Mosca and Tapp’s paper on amplitude amplification and estimation (quant-ph/0005055) and Cleve, Ekert, Macchiavello and Mosca’s “Quantum Algorithms Revisited” (quant-ph/9708016). I read abstracts, not the full papers. Every number in the worked examples was computed by me with numpy. Statements about the Deutsch–Jozsa query counts, parameter-shift rules, barren plateaus and typical usage are standard background that I did not look up, and are marked as such.

  1. Quantum Amplitude Amplification and Estimation (arXiv quant-ph/0005055, G. Brassard, P. Høyer, M. Mosca and A. Tapp) Abstract opened. About 1/√a rounds against 1/a, generalising Grover search, plus amplitude estimation and approximate counting.
  2. Quantum Algorithms Revisited (arXiv quant-ph/9708016, R. Cleve, A. Ekert, C. Macchiavello and M. Mosca) Abstract opened. Multi-particle interference, a common pattern, and algorithms as instances of quantum phase estimation.

Key terms in the dictionary