Curriculum / Quantum Algorithms / Grover's Search Algorithm

Lesson 3 of 12Code challengePro+150 XP

Grover's Search Algorithm

Search an unsorted database quadratically faster.

Grover's Search Algorithm

The Problem

You have an unsorted database of N items. One item is "marked", it satisfies some property f(x) = 1. You want to find it. You can only access the database through queries: present an item x, learn whether f(x) = 0 or 1.

Classically, you must query items one at a time. On average, you'll find the marked item after N/2 queries; in the worst case, N-1 queries. If N = 1,000,000, that's up to 500,000 queries on average.

Grover's algorithm finds the marked item in approximately queries, a quadratic speedup. For N = 1,000,000, that's ~785 queries instead of 500,000. For items (a problem no classical computer could ever touch), Grover's needs only queries.

This is a provably optimal quantum algorithm for unstructured search, no quantum algorithm can do better than for this problem.

What the oracle does, and doesn't, know

The oracle circuit marks the target state by flipping its phase: it applies -1 to |x⟩ and leaves all other states unchanged. Crucially, the oracle doesn't reveal which* item is marked, it just tags it with a phase. The quantum speedup comes not from the oracle but from the diffuser, which amplifies the tagged item by exploiting interference. The oracle is a black box; the speedup is in the circuit around it.

Geometric Intuition: Reflection About the Mean

After the oracle marks the target state, all amplitudes look like: states with amplitude , and one marked state with amplitude . The mean amplitude is:

The diffuser step performs "inversion about the mean": each amplitude is replaced by .

  • For the marked state:
  • For unmarked states:

This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.

How this lesson works

A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.

Part of: Quantum Algorithms

Learn the algorithms that make quantum computers powerful.

This lesson is part of Pro

Unlock Quantum Algorithms and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.