Description of Grover's algorithm
In this section, we'll describe Grover's algorithm. We'll begin by discussing phase query gates and how to build them, followed by the description of Grover's algorithm itself. Finally, we'll briefly discuss how this algorithm is naturally applied to searching.
Phase query gates
Grover's algorithm makes use of operations known as phase query gates. In contrast to an ordinary query gate defined for a given function in the usual way described previously, a phase query gate for the function is defined as
for every string
The operation can be implemented using one query gate as this diagram suggests:
This implementation makes use of the phase kickback phenomenon, and requires that one workspace qubit, initialized to a state, is made available. This qubit remains in the state after the implementation has completed, and can be reused (to implement subsequent gates, for instance) or simply discarded.
In addition to the operation we will also make use of a phase query gate for the -bit OR function, which is defined as follows for each string
Explicitly, the phase query gate for the -bit OR function operates like this:
To be clear, this is how operates on standard basis states; its behavior on arbitrary states is determined from this expression by linearity.
The operation can be implemented as a quantum circuit by beginning with a Boolean circuit for the OR function, then constructing a operation (i.e., a standard query gate for the -bit OR function) using the procedure described in the Quantum algorithmic foundations lesson, and finally a operation using the phase kickback phenomenon as described above. Notice that the operation has no dependence on the function and can therefore be implemented by a quantum circuit having no query gates.
Description of the algorithm
Now that we have the two operations and we can describe Grover's algorithm.
The algorithm refers to a number which is the number of iterations it performs (and therefore the number of queries to the function it requires). This number isn't specified by Grover's algorithm as we're describing it, and we'll discuss later in the lesson how it can be chosen.
Grover's algorithm
- Initialize an qubit register to the all-zero state and then apply a Hadamard operation to each qubit of
- Apply times the unitary operation to the register
- Measure the qubits of with respect to standard basis measurements and output the resulting string.
The operation iterated in step 2 will be called the Grover operation throughout the remainder of this lesson. Here is a quantum circuit representation of the Grover operation when
In this diagram, the operation is depicted as being larger than as an informal visual clue to suggest that it is likely to be the more costly operation. In particular, when we're working within the query model, requires one query while requires no queries. If instead we have a Boolean circuit for the function and then convert it to a quantum circuit for we can reasonably expect that the resulting quantum circuit will be larger and more complicated than one for
Here's a diagram of a quantum circuit for the entire algorithm when and For larger values of we can simply insert additional instances of the Grover operation immediately before the measurements.
Application to search
Grover's algorithm can be applied to the Search problem as follows:
- Choose the number in step 2. (This is discussed later in the lesson.)
- Run Grover's algorithm on the function using whatever choice we made for to obtain a string
- Query the function on the string to see if it's a valid solution:
- If then we have found a solution, so we can stop and output
- Otherwise, if then we can either run the procedure again, possibly with a different choice for or we can decide to give up and output "no solution."
Once we've analyzed how Grover's algorithm works, we'll see that by taking we obtain a solution to our search problem (if one exists) with high probability.