Quantum Algorithms: Grover, Shor & QFT Explained
A quantum algorithm is a finite sequence of unitary gates and measurements that uses superposition and interference to make a useful outcome likely, often followed by a short classical calculation.
This page is the map of the algorithm section. Five ideas carry a first course: Grover search, the amplitude amplification that generalizes it, the oracle those routines call, the quantum Fourier transform, and Shor’s factoring method. Each block below answers the same three questions. Which problem is the idea for? Which cost falls, and from what figure to what figure? What single picture makes that drop feel inevitable? Gate-level circuits stay on the linked lesson. The paragraphs here are the lines worth quoting, together with the hypotheses those lines depend on.
The speedups are specific. Grover’s quadratic improvement applies to search that has no usable structure. Shor’s polynomial runtime applies to factoring, through the period-finding problem factoring reduces to. A classical method that already uses sorting, a number-theoretic sieve, or dynamic programming is a different baseline, and the section states that baseline when it is a raw scan and when it is something tighter.
Grover’s algorithm
Grover’s algorithm is a quantum search procedure that finds a marked item in an unstructured collection by calling a yes-or-no checker about square-root as many times as a classical scan.
The problem is unstructured search. You are given candidate inputs and a function that returns 1 on the marked items and 0 on everything else. The set is not sorted, hashed, or generated by a formula you are allowed to exploit, so the legal move is to evaluate the checker. With one marked item, a classical scan uses on the order of evaluations in the worst case and about evaluations on average. Grover’s algorithm uses on the order of evaluations. For a million candidates and one marked item, that is a drop from about average checks to about checks. When items are marked, the classical count is on the order of and the quantum count is on the order of . The improvement is quadratic, and in the black-box query model that gap is optimal.
In one sentence, a phase flip on the marked states followed by a reflection about the average amplitude is a small rotation, and about of those rotations aligns the state with a marked item.
The diffuser and a two-qubit circuit are on the Grover search page. Extra iterations rotate past the target, and the success probability falls.
Amplitude amplification
Amplitude amplification is the quantum technique that raises the probability of a chosen good subspace by repeated reflections. Grover search is the special case whose starting state is the uniform superposition.
The problem is amplified sampling. A unitary prepares a state that already has success probability of lying in the good subspace, and a checker recognizes that subspace. Classically you repeat the preparation until a trial lands in the good subspace, which takes on the order of trials. Amplitude amplification calls , its inverse, and the checker on the order of times and lifts the success probability to a constant. When the start is uniform and one item out of is good, , and the drop matches Grover: from on the order of trials down to on the order of trials. If a heuristic quantum routine already succeeds with probability , amplification cuts the expected repetitions from about to about . The useful iteration count is about where .
In one sentence, two reflections compose into one rotation in the plane spanned by the good state and the state orthogonal to it, so each iteration walks toward the answer.
When is unknown, the basic count can overshoot. Estimating the angle, or switching to a fixed-point variant that keeps the probability climbing as iterations are added, is covered with the reflection formulas on the amplitude amplification page.
Quantum oracles
A quantum oracle is a reversible circuit that recognizes whether an input is a solution and marks that fact on the quantum state, usually by a phase flip.
The problem it solves is representation. Grover’s algorithm and amplitude amplification both assume a checker that equals 1 on solutions and 0 elsewhere, and a quantum circuit can apply only unitaries. The phase oracle is the unitary defined by : marked basis states receive a minus sign, and every other basis state stays unchanged. The bit oracle writes the bit into an ancilla, . Prepare that ancilla in and phase kickback converts the bit oracle into the phase oracle. The complexity drop is in the number of calls, because one call still costs one evaluation of , the same order as one classical test. Unstructured search then falls from on the order of evaluations to on the order of evaluations, once each evaluation is an efficient reversible circuit and every scratch qubit is returned to . Scratch qubits left entangled with the input erase the interference, so the measured distribution never shows the saving.
In one sentence, the oracle writes a minus sign on solutions, and later interference turns that sign into a large measurement probability.
A controlled-Z that marks , and a small Boolean checker built the same way, are on What is an oracle?.
The quantum Fourier transform
The quantum Fourier transform (QFT) is the unitary change of basis that rewrites a computational-basis integer as a superposition of phase-weighted basis states, the same change of basis as the discrete Fourier transform.
The problem it solves is moving information from an index into a frequency so that phase estimation and period finding can read it. On qubits, with ,
A classical discrete Fourier transform writes down all complex outputs. The direct product costs on the order of arithmetic operations, and the fast Fourier transform brings that down to on the order of . The QFT circuit, a ladder of Hadamard gates and controlled phase rotations, uses on the order of elementary gates, which is . On 20 qubits that is a few hundred gates, against about operations for an FFT of the same length. The circuit prepares an -qubit state, and a measurement draws one index from the frequency distribution. Phase estimation needs that single draw. A printed table of every coefficient is a separate task, still performed by the classical FFT at cost.
In one sentence, Hadamards and controlled phases copy the input integer into relative phases, which is the shape a hidden period or an eigenphase already has.
A three-qubit gate list is on the quantum Fourier transform page. Shor’s algorithm applies the inverse, the same ladder with the rotation angles negated.
Shor’s algorithm
Shor’s algorithm is a hybrid method that factors an integer by finding the period of on a quantum computer and converting that period into factors with classical gcd arithmetic.
The problem is integer factoring, reduced to order finding. Choose an integer coprime to and find the smallest positive integer such that . When is even and , the two gcd values are nontrivial factors. Classical trial division up to takes time exponential in the bit length : doubling the number of bits squares the number of candidates you must try. The number field sieve, the general classical method used for large integers, improves that to a subexponential cost that is still superpolynomial in . Shor’s period finding is polynomial in . Modular exponentiation dominates the gate count and is commonly placed on the order of gates with schoolbook reversible arithmetic; the inverse QFT after it is the smaller term. Continued fractions recover a candidate period from the measured phase, and a few gcd checks either return the factors or ask for a new base .
In one sentence, the powers hide their period in a phase, and the Fourier transform turns that phase into an integer a measurement can return.
The classical–quantum–classical workflow, and the scale of fault-tolerant hardware cryptographic sizes require, are on Shor’s algorithm.
How the five ideas connect
Search by amplification and period finding by the Fourier transform are two families that share interference and a reversible encoding of the answer.
Grover, the oracle, and amplitude amplification proceed through the whole search family. The oracle marks a subspace, two reflections rotate toward it, and Grover is that rotation started from the uniform superposition. Substitute another preparation and the same geometry applies at a different angle . Shor’s family runs along the other path. Reversible modular exponentiation writes a periodic function into a register, phase estimation stores the period as an eigenphase on a control register, and the inverse QFT converts that phase into a basis state. Classical gcd arithmetic then finishes the factoring. Both families hide the answer in a phase and let interference raise its measurement probability. The phase pattern differs: a single minus sign on each marked basis state in the search family, and a progression of roots of unity in the period-finding family. The shared prerequisite for seeing where either phase comes from is phase kickback. The circuits after that point stay distinct, so the Grover lesson and the Shor lesson each still need their own pass.
A useful test of the split is which resource you would add if the algorithm slowed down. A slower Grover run wants a cheaper checker or fewer marked-item guesses. A slower Shor run wants a cheaper modular multiplication; shrinking the QFT changes the total far less, because the transform is the smaller term.
Query cost and gate cost
Query cost counts calls to a checker or a state preparation. Gate cost counts every elementary operation, including the work hidden inside each call.
The Grover and amplitude-amplification drops above are query drops: checker calls, or uses of a preparation. They become statements about runtime once each call is an efficient circuit whose scratch space returns to zero. An oracle that itself scans a list of size would spend linear work per call and would hand the quadratic saving back. The QFT drop is a gate count from the start, from operations that emit every Fourier coefficient to gates that prepare an -qubit state. Shor’s polynomial bound is a gate count too, and modular multiplication supplies most of those gates. Error correction multiplies logical gate counts by a physical overhead that depends on the code and the physical error rate. The same quadratic query improvement can be genuine in a fault-tolerant cost model and still sit beyond present noisy devices, because the depth exceeds the coherence time. When you compare an algorithm paper with a hardware estimate, take the query figure and the gate figure from the same ledger, and say which one you are quoting.
Complexity at a glance
Unstructured search drops quadratically, from on the order of checks to on the order of checks, and factoring drops from a superpolynomial classical cost to a cost polynomial in the number of bits.
| Idea | Problem | Classical cost | Quantum cost |
|---|---|---|---|
| Grover | One marked item among | checks | checks |
| Amplitude amplification | Success probability | trials | trials |
| Oracle | Recognize a solution | One evaluation per call | One evaluation per call; search then uses calls |
| QFT | Fourier change of basis, | to emit all coefficients | gates to prepare the state |
| Shor | Factor an -bit integer | Superpolynomial (number field sieve); trial division is exponential in | Polynomial in |
Read each row beside its section. The oracle row is a unit price. The saving appears after Grover or amplitude amplification decides how many times to pay it. The QFT row compares two outputs: a full table of complex numbers, and an -qubit state you measure once. Shor’s row is the scaling of the whole factoring pipeline with the bit length. Taking trial division as the classical column makes the gap look like exponential versus polynomial; taking the number field sieve makes it superpolynomial versus polynomial. Both comparisons are used in the literature, and they answer different questions. Trial division is the cost of the obvious method. The sieve is the cost of the best general method now in use.
Where to read next
Read Grover first, then the oracle and amplitude amplification, then the quantum Fourier transform, and Shor last.
Grover is the shortest complete argument: one checker, one diffuser, a stated iteration count, and a quadratic gap visible on four basis states. The oracle lesson shows the checker as a circuit you compile, including the uncomputation that clears scratch qubits. Amplitude amplification separates the uniform start, which belongs to Grover, from the pair of reflections, which is the general engine. The QFT lesson turns Shor’s last register into a concrete gate list. Shor’s lesson then stacks phase estimation, the inverse transform, and the classical conditions on the period. Stay on this page when you need a definition and the complexity change. Open the linked lesson when you need to edit a circuit or check an iteration count.