Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 30

Grover's Algorithm and Unstructured Search

Recommended resources

Hello! In our last lesson, we successfully implemented the Bernstein-Vazirani algorithm in Qiskit, seeing firsthand how a quantum computer can solve a specific promise problem with a single query. That algorithm demonstrated an exponential speedup, but it applies to a very narrow task.

Today, we shift our focus to a much more general and widely applicable problem. This lesson introduces Grover's search algorithm, one of the cornerstones of quantum computing. Our goal is to describe the unstructured search problem and the quadratic speedup provided by Grover's algorithm. We'll explore what it means to search without any clues and see just how much faster a quantum computer can perform this fundamental task.


1. The Unstructured Search Problem

Imagine you have a massive, unsorted phone book and you need to find the name corresponding to a specific phone number. There's no alphabetical order to help you; your only option is to check each entry one by one until you find a match. This is the essence of an unstructured search.

In more formal terms, we have a list of items and a "black box" function, called an oracle, that can tell us if an item is the one we're looking for. The problem is "unstructured" because we have no information about where the solution might be.

To start, let's read a brief introduction that defines this problem and its classical limitations.

Grover's algorithm | IBM Quantum Learning

This text from IBM Quantum Learning clearly defines the unstructured search problem and uses the phone book analogy to make it concrete.

Read the "Introduction" and the first two paragraphs of the section that follows it. Pay close attention to the definition of the problem and the distinction between a structured and unstructured search.

The classical approach is straightforward, as illustrated below. You test items one by one.

Classical Unstructured Search Problem
This diagram from the IBM Quantum Learning page illustrates the classical method for unstructured search. An oracle checks items from a bin of inputs one by one to see if the output is '1' (a solution) or '0' (not a solution).

On average, you'd expect to check about half the items () before finding the correct one. In the worst case, you might have to check all items. In computer science, we say the time complexity of this classical search is , meaning the time it takes grows linearly with the number of items.


2. Quantum Advantage: The Quadratic Speedup

This is where Grover's algorithm changes the game. Instead of taking steps, it can find the marked item in approximately steps. This is known as a quadratic speedup.

While not as dramatic as the exponential speedup we saw with Bernstein-Vazirani, a quadratic speedup is still incredibly powerful for large search spaces.

To get a better feel for this, let's watch a video from 3Blue1Brown that masterfully explains the problem and the nature of the speedup.

But what is quantum computing? (Grover's Algorithm)

This video provides an excellent and intuitive introduction to the unstructured search problem and the speedup from Grover's algorithm.

Watch the segment from the beginning up to the discussion of the speedup. As you watch, focus on these key points: The common (but incorrect) intuitions about how a quantum computer would solve this. The correct runtime complexity: O(\sqrt{N}). The difference between a quadratic and an exponential speedup.

As the video highlighted, a common misconception is that a quantum computer "tries all possibilities in parallel" and instantly finds the answer. This would imply an runtime, which is not the case. The actual speedup is more subtle and powerful.

To put this into perspective:

  • To search a list of 1 million items, a classical computer needs, on average, 500,000 checks.
  • A quantum computer using Grover's algorithm would need about steps.
  • To search a list of 1 trillion items, a classical computer needs 500 billion checks.
  • Grover's algorithm would need about 785,000 steps.

The difference becomes more dramatic as the search space grows. This graph provides a clear visual comparison between a linear and a quadratic relationship.

Comparison of Linear vs. Quadratic Speedup
This plot visualizes the efficiency gain from a quadratic speedup. The number of steps for the quadratic algorithm (red line, like Grover's) grows much more slowly than for the linear algorithm (blue line, like classical search).

For a slightly more formal reinforcement of this concept, let's watch a brief segment from a Qiskit lecture.

Grover's Algorithm | Understanding Quantum Information & Computation | Lesson 08

This Qiskit video explicitly compares the classical and quantum query complexities for unstructured search.

Please watch the section that compares classical and quantum costs. It directly states the number of queries needed for deterministic, randomized, and quantum approaches.


3. How is This Speedup Possible? A Glimpse of the Mechanism

So, if it's not "magic parallelism," how does Grover's algorithm achieve this speedup? The full details are for our next lesson, but the core idea is a process called amplitude amplification.

Recall from our previous lessons that a qubit's state is described by amplitudes, and the probability of measuring a state is the square of its amplitude's magnitude. Grover's algorithm starts by putting all possible answers in an equal superposition, where each has a small, identical amplitude. Then, it iteratively performs two steps:

  1. The Oracle: The oracle "marks" the solution by flipping the sign of its amplitude (e.g., from positive to negative). This is a phase kickback, similar to what we used in the Bernstein-Vazirani algorithm. This phase change is initially invisible to measurement.
  2. The Diffusion Operator: A clever sequence of gates then amplifies the amplitude of the marked item while shrinking the amplitudes of all other items.

This process is like a "rotation" in a high-dimensional vector space, which gradually moves the state vector from the initial equal superposition towards the solution state. The following video segment gives a beautiful geometric intuition for this process.

But what is quantum computing? (Grover's Algorithm)

This part of the 3Blue1Brown video visualizes the algorithm as a series of geometric rotations and explains how the O(\sqrt{N}) runtime emerges from this picture.

Watch from the start of the geometric visualization up to the calculation of the number of steps. Focus on understanding the two main operations as reflections and their combined effect as a rotation.

The key insight is that each iteration of the oracle and diffusion operator rotates the state vector by a small angle, bringing it closer to the solution. The number of rotations needed to get "close enough" to the solution turns out to be proportional to . This is where the quadratic speedup comes from.



Conclusion

In this lesson, we've laid the conceptual groundwork for understanding Grover's search algorithm. We've moved from the specific promise problems of our previous lessons to the general and highly practical problem of unstructured search.

Key Takeaways:

  • Unstructured search is the problem of finding a specific item in an unsorted list of items, equivalent to finding an input that makes an oracle function return 'true'.
  • Classically, this requires steps, as there is no better strategy than checking items one by one.
  • Grover's algorithm provides a quadratic speedup, solving the problem in only steps.
  • This speedup is achieved not by simple parallel checking, but by a quantum process called amplitude amplification, which iteratively increases the probability of measuring the correct answer.

Preview of the Next Lesson:
Now that we understand what Grover's algorithm does and how much of a speedup it offers, our next step is to explore how it works in more detail. In the next lesson, we will dissect the two main components of the algorithm: the oracle and the diffusion operator (amplitude amplification). We will then learn how to construct the oracle for a simple search problem in Qiskit.