Advanced Mathematics

Grover's and Shor's Algorithms

Grover's algorithm searches NN items in about N\sqrt N steps; Shor's factors large numbers fast by finding a period with the quantum Fourier transform.

Needs a step first: 44

Grover's algorithm starts in an equal superposition, flips the sign of the marked item, then reflects every amplitude about the mean; each round moves amplitude towards the answer, and about π4N\frac\pi4\sqrt N rounds find it, a square-root speed-up over checking one by one. Shor's algorithm reduces factoring NN to finding the period rr of ax mod Na^x \bmod N, which the quantum Fourier transform reads off through interference; then gcd⁡(ar/2±1,N)\gcd(a^{r/2} \pm 1, N) usually gives a factor. Since RSA's security rests on factoring being hard, a large enough quantum computer would break it, while Grover only halves the effective key length of symmetric ciphers, which longer keys fix.

Where it shows up: Shor's algorithm is why cryptographers design post-quantum ciphers, and Grover's idea of amplifying amplitudes recurs throughout quantum computing.

How to hold it: In your head

See Grover as repeatedly flipping and reflecting amplitudes towards the answer and Shor as interference revealing a period, and know why one gives only a square-root speed-up while the other breaks RSA.

What knowing it looks like

  • Run one Grover iteration on four items by hand and track every amplitude.
  • Find the period of 7x mod 157^x \bmod 15 and use it to factor 15 as Shor's algorithm would.
  • Explain what a square-root speed-up does and does not buy compared with Shor's.

Test yourself

Grover search over N=4N = 4 items, with item ∣11⟩|11\rangle marked. Start in the equal superposition (every amplitude 12\tfrac12). Apply the oracle, which flips the sign of the marked amplitude, then the diffusion step, which replaces each amplitude α\alpha by 2αˉ−α2\bar\alpha - \alpha, where αˉ\bar\alpha is the mean amplitude. What are the amplitudes now, and what is the probability of measuring ∣11⟩|11\rangle?
Show the worked answer
After the oracle: (12,12,12,−12)(\tfrac12, \tfrac12, \tfrac12, -\tfrac12). The mean is αˉ=14(32−12)=14\bar\alpha = \frac{1}{4}(\tfrac32 - \tfrac12) = \tfrac14. Diffusion: unmarked amplitudes become 2⋅14−12=02\cdot\tfrac14 - \tfrac12 = 0, and the marked one becomes 2⋅14+12=12\cdot\tfrac14 + \tfrac12 = 1. So the state is exactly ∣11⟩|11\rangle and it is found with probability 1, after a single query, where a classical search needs up to 3.

Needs a step first: 44

Learn it with an AI

Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.

Be my maths tutor. I'm learning "Grover's and Shor's Algorithms" (Frontier tier): Grover's algorithm searches $N$ items in about $\sqrt N$ steps; Shor's factors large numbers fast by finding a period with the quantum Fourier transform.
I already know: Entanglement, The Fourier Transform, Modular Arithmetic and Primes.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: Grover search over $N = 4$ items, with item $|11\rangle$ marked. Start in the equal superposition (every amplitude $\tfrac12$). Apply the oracle, which flips the sign of the marked amplitude, then the diffusion step, which replaces each amplitude $\alpha$ by $2\bar\alpha - \alpha$, where $\bar\alpha$ is the mean amplitude. What are the amplitudes now, and what is the probability of measuring $|11\rangle$?
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.

On the way to

Recommended