Why It Beats Classical Factoring
This module has built Shor's algorithm layer by layer. Now it is time to step back and ask the central question: exactly how much faster is it? The gap between Shor's algorithm and the best classical factoring methods is not a modest improvement — it is an exponential chasm, and understanding why requires a careful comparison of the two computational models.
The classical benchmark: the General Number Field Sieve
The fastest known classical algorithm for factoring an integer is the General Number Field Sieve (GNFS). Its heuristic running time on a machine performing one operation per clock cycle is
where is a small constant. This is sub-exponential in but still grows much faster than any polynomial in . In computational complexity language it is written using the -notation for sub-exponential algorithms.
To make the scaling concrete, let be the bit length of (the natural input size). Then , so
This is a function that grows faster than any polynomial in but slower than . Doubling multiplies the cost by , a very large factor.
Shor's algorithm: polynomial in the bit length
Shor's quantum algorithm for factoring runs in time
elementary quantum gate operations, where the cost comes almost entirely from the modular-exponentiation subroutine , which requires controlled modular multiplications each costing gates. The inverse Quantum Fourier Transform adds gates, which is dominated by the cost of . The initial Hadamard layer and measurement add only steps.
The algorithm must be repeated a small constant number of times to boost the probability that the classical post-processing step (continued fractions plus GCD) successfully extracts the factors. The expected number of repetitions is , so the total cost is
This is polynomial in , placing integer factoring in the complexity class (bounded-error quantum polynomial time).
The exponential gap
The ratio of the two running times illustrates how large the advantage is:
As , the numerator grows super-polynomially while the denominator is polynomial, so the ratio diverges. In formal terms, for every polynomial there exists such that for all ,
This is what computer scientists mean by an exponential speedup: the quantum algorithm achieves a speedup larger than any fixed polynomial.
For concrete numbers, consider RSA-2048 ():
- GNFS estimate: operations (infeasible with all classical hardware ever built).
- Shor estimate: quantum gate operations per repetition (feasible for a large fault-tolerant quantum computer after error correction overhead is included, though the physical qubit count in that regime is in the millions).
Why the QFT creates the speedup
The heart of the speedup is the Quantum Fourier Transform's ability to detect the period of the function using only gates, whereas the best classical algorithm for period-finding costs at least steps (by a birthday-paradox lower bound).
Classically, to find the period of a function, you must evaluate it enough times to notice a repetition. By the birthday paradox, you need evaluations before a collision is likely. Since can be as large as (the Carmichael function), this is at least evaluations — exponential in .
Quantumly, the period-finding subroutine prepares a superposition of all inputs simultaneously in a single pass, then applies the inverse QFT to concentrate the measurement probability on integer multiples of . A single measurement (plus continued-fraction extraction) reveals with probability. No classical evaluation-and-wait strategy can replicate this: the QFT exploits the interference between amplitudes to perform, in effect, a global Fourier analysis in steps. Classical fast Fourier transforms require operations because they must process all function values explicitly.
Scaling behavior: a table
The table below shows estimated raw gate counts (ignoring constants) for several bit lengths , comparing GNFS against the quantum gate count for Shor's algorithm before fault-tolerance overhead.
| Bit length | GNFS cost (approx.) | Shor gate count () | |:-:|:-:|:-:| | 128 | | | | 512 | | | | 1024 | | | | 2048 | | |
The GNFS column uses the standard estimate with . Even ignoring error-correction overhead, the asymptotic advantage of the quantum algorithm is unmistakable.
Implications for cryptography
RSA key lengths have grown over time to stay ahead of classical advances in GNFS. 1024-bit RSA was deprecated around 2013 and 2048-bit RSA is the current standard. But longer keys only delay the problem: because the GNFS cost is sub-exponential, doubling the key length provides a large but eventually exhausted buffer. Shor's algorithm eliminates the buffer entirely — for any fixed key length, a sufficiently powerful quantum computer can factor in polynomial time.
This is why the cryptographic community is transitioning to post-quantum cryptography: schemes based on lattice problems, hash functions, and other mathematical structures for which no quantum speedup comparable to Shor's is known. The transition is underway at standards bodies including NIST (which finalized its first post-quantum standards in 2024), driven directly by the complexity analysis covered in this lesson.
Summary
| Property | GNFS (classical) | Shor's algorithm (quantum) | |:--|:-:|:-:| | Time complexity | (sub-exponential) | (polynomial) | | Scales as key doubles | cost increases by factor | cost increases by factor | | Key insight | Algebraic number sieves | QFT detects periodicity via interference | | Threat to RSA-2048 | No practical threat today | Decisive threat on fault-tolerant hardware |
The exponential speedup from polynomial-time quantum period-finding over sub-exponential classical sieving is the engine behind every cryptographic concern about large-scale quantum computers. It is also one of the most striking demonstrations of the power of quantum interference — and a complete proof that is not contained in would resolve one of the deepest open questions in computational complexity theory.
Sign in on the full site to ask questions and join the discussion.