Conceptual, not a course: enough to understand why Shor’s and Grover’s algorithms are the two quantum results that actually matter for competitive programmers (one threatens the cryptography other notes rely on, the other gives a provable speed limit on complete search). No quantum circuit will ever run on a judge; this is background, not technique.
The model, briefly
A classical bit is 0 or 1. A qubit is a unit vector with ; measuring it collapses to with probability , with probability , destroying the superposition. qubits hold a superposition over all basis states simultaneously — this is the source of every “quantum speedup” claim, and also the source of most quantum-computing hype: you cannot simply read out an exponential amount of information, because measurement collapses to one basis state. Every useful quantum algorithm has to engineer interference (amplitudes that cancel for wrong answers and reinforce for right ones) so that measurement is likely to land on something useful.
Quantum gates are unitary (reversible) transformations on the amplitude vector — contrast with classical logic gates like AND/OR, which are not reversible (you can’t recover the inputs from the output). This reversibility is why quantum circuits are built from gates like Hadamard (creates superposition), CNOT (entanglement) and phase rotations, rather than classical Boolean gates directly.
Grover’s algorithm: quadratic speedup for unstructured search
Problem: given a black-box function with exactly one satisfying , find . Classically this needs queries in the worst case — no cleverness helps without structure, which is exactly the setting of unstructured backtracking before any pruning is possible.
Grover’s algorithm finds it in queries, by repeatedly applying an “oracle + diffusion” step that rotates the amplitude vector slightly toward ; after iterations, measuring yields with probability close to 1.
Proof sketch: why iterations suffice (geometric picture)
Represent the state as a vector in the 2D plane spanned by (the target) and the uniform superposition over the rest, starting at angle from the “non-target” axis with (the initial uniform superposition’s overlap with the target). Each Grover iteration is a fixed rotation by toward the target (reflection through “non-target”, then reflection through the initial state composes to a rotation, a standard two-reflections-equal-a-rotation fact). Reaching angle (measurement overwhelmingly likely to give ) takes iterations; since for small , that’s iterations. (Full treatment needs the explicit unitary matrices; this is the standard “two reflections” argument used in every quantum computing course, included here for the shape of the idea, not as original work.)
This quadratic speedup is provably optimal (the BBBV lower bound: no quantum algorithm solves unstructured search in fewer than queries) — unlike Shor’s algorithm below, Grover’s isn’t just “the best known,” it’s a proven floor. Practical takeaway for a competitive programmer: Grover’s algorithm is the formal reason “quantum computers will just brute-force NP-hard problems” is wrong — is still exponential, only the exponent is halved, the same way meet-in-the-middle halves a classical exponent.
Shor’s algorithm: why it breaks RSA
Factoring reduces to finding the period of for a random (once the period is known, usually reveals a factor, assuming is even and — both hold with probability for random , so a few retries succeed with overwhelming probability).
Classically, finding this period needs exponential time (essentially as hard as factoring itself — no classical shortcut is known). Quantumly, period-finding is efficient: put the exponent register in superposition over all , compute into a second register (entangling the two), then apply the quantum Fourier transform to the exponent register — since is periodic with period , the QFT concentrates amplitude on multiples of (the quantum analogue of how an ordinary Fourier transform of a periodic signal concentrates on multiples of the fundamental frequency), and measuring recovers (or a value close enough to extract it via continued fractions) with high probability, in time.
The same period-finding machine also solves discrete log, which is why Shor’s algorithm threatens both RSA and Diffie–Hellman at once: both their hardness assumptions reduce to a period-finding problem that is classically hard but quantumly easy. This is not a proof that or that quantum computers solve NP-hard problems in general — factoring is not known (or believed) to be NP-hard, and Shor’s algorithm is highly specific to the algebraic structure of modular exponentiation. It does not speed up NP-complete problems the way Grover’s algorithm’s quadratic speedup applies generically.
Where quantum computing is and isn’t relevant to CP
| Claim | True? |
|---|---|
| Quantum computers will make backtracking into | no — Grover gives , still exponential |
| Quantum computers will break RSA/Diffie–Hellman once large enough | yes, via Shor’s algorithm (requires a fault-tolerant machine far beyond current hardware) |
| Quantum computers prove | no — believed false; (quantum poly-time) is not known or believed to contain all of NP |
| A CP judge will ever run quantum code | no, not in any foreseeable contest format |
| Understanding this helps explain a note elsewhere in this repo | yes — specifically why [[24-beyond-cp/05-cryptography-fundamentals |
Related notes
- Cryptography Fundamentals — what Shor’s algorithm threatens, and why.
- Complexity Theory and NP-Hardness — where sits relative to P, NP and PSPACE (believed , with vs unresolved either direction).
- Backtracking and Pruning — the classical unstructured-search setting Grover’s algorithm applies to.