Learn/Grover's Search
Intermediate10 min read

Grover's Search: Quantum Speedup

Find a marked item in an unsorted database quadratically faster than any classical algorithm.

The Speedup

ItemsClassicalGrover
4~21
1,000~50032
1,000,000~500,0001,000

The Code

grover.ql
# Grover's Algorithm - Search for |11⟩
QUBIT q0, q1
c0 = 0
c1 = 0
 
# Superposition
H(q0)
H(q1)
 
# Oracle (marks |11⟩)
CZ(q0, q1)
 
# Diffusion operator
H(q0)
H(q1)
X(q0)
X(q1)
CZ(q0, q1)
X(q0)
X(q1)
H(q0)
H(q1)
 
# Measure
MEASURE q0 -> c0
MEASURE q1 -> c1

How It Works

1. Superposition

Hadamard gates create equal superposition of all 4 states (00, 01, 10, 11) - each with 25% probability.

2. Oracle

The CZ gate "marks" the target state |11⟩ by flipping its phase. This is invisible but crucial.

3. Diffusion

The diffusion operator amplifies the marked state while suppressing others. After one iteration, |11⟩ has 100% probability!

Key Insight

Grover's algorithm achieves quadratic speedup: O(√N) vs O(N). For a database of 1 million items, that's 1,000 quantum operations vs 500,000 classical checks.

Try It Yourself

python qubitlang_cli.py run grover.ql --shots 1024Request Files