Quantum Search

Let's learn about quantum search and how it is faster than its classical counterpart.

Grover’s Algorithm was proposed by Lov Grover in 1996. Like the Deutsch-Jozsa Algorithm, a quantum algorithm is empirically faster than our fastest classical solution to the same problem. How much faster? Grover’s Algorithm provides a quadratic speedup over its classical counterpart. While at first sight, it is not as remarkable as the exponential speedup of the DJ Algorithm, one can argue that Grover’s solution is immediately useful and provides a great blueprint for solving similar problems.

The problem that Lov Grover solved using his algorithm is related to searching an unordered collection of items. Imagine an unordered list of elements from which we want to search for a particular item. For example, in the following array, we want to find -6, the second-to-last element.

%0 node_1622033461566 41 node_1622033326478 412 node_1 1 node_2 -12 node_3 897 node_1622033279589 -9 node_1622033358636 420 node_1622033359218 0 node_1622033370274 1 node_1622033308944 7 node_1622033330954 -56 node_1622033396769 6 node_1622033358110 -56 node_1622033370247 24 node_1622033461082 71 node_1622033472290 -6 node_1622033430678 66
An unordered collection of items.

Take a moment and think about how you would approach this problem classically. Take the general case and ask yourself:

  • What’s the fastest way to find an element in an unordered collection?

Classical solution

Since there is no internal structure or metadata that we can use to speed up our search, the best we can do classically is a linear search. In a linear search, we start from the beginning of the list and iterate over all elements. In each iteration, we inspect the current element and see if that is the one that we were looking for initially. If we have encountered that item, great, we stop our search. Otherwise, we move ahead and check the rest of the list until the last element. What’s the time complexity of such a solution? If we’re lucky, the first item we inspect is the one we sought. In that case, the complexity is O(1)O(1). In the worst case, we iterate through the list, and either the element is right at the end, or it does not exist at all. In that case, the time complexity is O(N)O(N). So, in the average case, we’ll have to inspect 50%50\% or N2\frac{N}{2} elements of the list.

It genuinely seems like this is the best we can do no matter how we approach the problem. But that would be myopic on our part. We can solve this problem much faster on a quantum computer using Grover’s Algorithm, which has an asymptotic time complexity of O(N)O(\sqrt{N}).

At this point, some people might argue that binary search with O(log N)O(log\space N) complexity after sorting the data would be much faster than the proposed O(N)O(\sqrt{N}). But there are two things we need to remind ourselves of here. Sorting this array would most probably ...

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy