You are given a list of numbers and a target number, and you are asked to find the index in the list at which the target number appears. If the list is sorted, you can use search algorithms such as binary search. But if the list is not sorted, there isn’t really much you can do; you simply have to traverse the whole list till you find the element. In terms of algorithmic complexity, this takes O(N) time. With a quantum computer, however, you can solve this problem in just O(√N) time. This article explains how this is achieved by the Grover’s search algorithm.

_If you’re new to quantum computing, you should first read this short primer: _Quantum parallelism — where quantum computers get their mojo from.

Image for post

Needle in a haystack (Image from Pixabay)

Let’s start by framing the problem. We are given:

  • A set of N elements X = {x_1, …, x_i, … ,x_N} such that each x_i is an m-bit string made of 0s and 1s.
  • A target element x* that is also an m-bit string made of 0s and 1s
  • A function _f _that takes as input an m-bit string and returns 1 if the string is x* and 0 otherwise. This function can be written as:

Image for post

Grover’s search works in three steps as described below.

Step 1: Setup the state

A quantum state is set up in an equal superposition of the basis states. As an example, consider N=8. We set up the state using 3 qubits as:

Image for post

#search #machine-learning #algorithms #quantum-computing #algorithms

Finding the needle in a haystack on a quantum computer
1.30 GEEK