Quantum
Module 7 · Algorithms · Lesson 3

Simon's algorithm

The first exponential quantum speedup robust to randomness. A direct ancestor of Shor's algorithm.

8 min read · Lesson 23 of 32

Simon’s problem (1994) is the first example of a problem where the quantum algorithm is exponentially faster than the best possible classical algorithm, even if the classical algorithm uses randomness. This was a huge deal at the time — Deutsch-Jozsa’s speedup depended on insisting on zero error, but Simon’s speedup doesn’t. It’s genuine.

And historically, Simon’s algorithm is the direct ancestor of Shor’s factoring algorithm. The core idea — using the quantum Fourier transform to extract hidden periodicity — is the same in both.

The problem

You’re given f:{0,1}n{0,1}nf: \{0,1\}^n \to \{0,1\}^n with the promise that there exists a hidden period s{0,1}ns \in \{0,1\}^n, s0s \neq 0, such that:

f(x)=f(y)    x=y or x=ysf(x) = f(y) \iff x = y \text{ or } x = y \oplus s

In words: ff is 2-to-1, and two inputs map to the same output if and only if they differ by ss. Your job: find ss.

The classical lower bound

Think about how you’d approach this classically. You need to find two distinct inputs x,yx, y such that f(x)=f(y)f(x) = f(y) — then s=xys = x \oplus y. This is essentially a collision search.

By the birthday paradox, you expect to find a collision after about 2n=2n/2\sqrt{2^n} = 2^{n/2} queries. That’s still exponential in nn. And this is actually the best classical algorithm (with or without randomness): any classical algorithm needs exponentially many queries.

The quantum algorithm

Quantum algorithm: O(n)O(n) queries. That’s polynomially many — an exponential speedup, no caveats.

The structure is, again, “Hadamard, oracle, Hadamard”:

  1. Initialize 2n2n qubits: nn “input” and nn “output” registers, all in 0|0\rangle.
  2. Apply HH to each input qubit: uniform superposition on the input register.
  3. Apply the oracle: x0xf(x)|x\rangle|0\rangle \mapsto |x\rangle|f(x)\rangle.
  4. Measure the output register. This leaves the input register in a superposition of exactly two values: x+xs|x\rangle + |x \oplus s\rangle for some random xx.
  5. Apply HH to each input qubit.
  6. Measure the input register. The measurement outcome yy satisfies ys=0(mod2)y \cdot s = 0 \pmod 2.

A single run yields one linear equation in ss (over F2\mathbb{F}_2). Repeat the algorithm n1n - 1 times to get n1n - 1 independent linear equations, and solve the resulting linear system to find ss.

Why it works

After step 4, the input register holds an equal superposition of the two inputs that share the measured output value:

12(x+xs)\frac{1}{\sqrt{2}}(|x\rangle + |x \oplus s\rangle)

Apply HnH^{\otimes n}:

Hnx+Hnxs=12ny((1)xy+(1)(xs)y)yH^{\otimes n}|x\rangle + H^{\otimes n}|x \oplus s\rangle = \frac{1}{\sqrt{2^n}} \sum_y \big((-1)^{x \cdot y} + (-1)^{(x \oplus s) \cdot y}\big) |y\rangle

Factor the phase:

=12ny(1)xy(1+(1)sy)y= \frac{1}{\sqrt{2^n}} \sum_y (-1)^{x \cdot y}\big(1 + (-1)^{s \cdot y}\big) |y\rangle

The amplitude on y|y\rangle is zero unless sy=0(mod2)s \cdot y = 0 \pmod 2. So measurement always yields a yy orthogonal (in F2\mathbb{F}_2) to ss. Collect n1n - 1 such yys, and you can solve for ss up to the one-dimensional null space.

Why it matters

Simon’s algorithm is the template for Shor’s factoring algorithm. Shor’s insight was: factoring a number NN reduces to finding the period of the function f(x)=axmodNf(x) = a^x \mod N for a randomly chosen aa. The quantum Fourier transform generalizes Simon’s Hadamard trick from the group (Z/2)n(\mathbb{Z}/2)^n to Z/M\mathbb{Z}/M, which is exactly what you need to extract periodic structure from modular exponentiation.

Simon’s isn’t the headline algorithm, but it’s the one that convinced Shor the approach would work on a deeper problem.

Quick check
What classical lower bound does Simon's algorithm beat?
Quick check
What's the relationship between Simon's algorithm and Shor's algorithm?

What’s next

Grover’s search is the other famous quantum algorithm. It’s not exponentially faster than classical, but it gives a quadratic speedup for an enormous class of problems: unstructured search. This is the algorithm you get to actually see running in the next lesson.