Grover's Algorithm and the Unstructured Search Problem
The Unstructured Search Problem
For the purposes of this lesson, the unstructured search problem is defined by a function that maps binary strings of length to a single bit. We are searching for a solution, which we define as a binary string of length that causes to evaluate to one. This is generally a very difficult computational problem; specifically, if the input is a description of a boolean circuit for computing the function , it is an NP-complete problem. We can formalize this as a query problem, which is reasonable within the context of the query model. However, in practice, it is natural to think of as being computed by a Boolean circuit. As seen in lesson six, we can connect these viewpoints by converting a Boolean circuit into a quantum circuit to implement a query operation.
In this problem, the input is the function , and we seek a solution if one exists. If is the constant zero function, the correct output is to report that no solutions exist. This is termed an "unstructured" search problem because there is nothing special about that facilitates finding a solution, unlike searching through ordered data or data structures. An analogy is searching for a phone number in a phone book versus searching for a name; the latter is easier because names are alphabetized. This represents searching for a solution to a complicated equation or a combination for a lock. While oracles and black boxes do not exist in real life, complicated Boolean circuits are essentially black boxes to us. For notation, we let be the length of the input strings and be the total number of input strings.
Classical and Quantum Search Costs
Classically, the search problem can be solved by iterating through all possible -bit strings and evaluating on each. If a solution is found, the process stops. In the worst case, this requires queries. This is the best a deterministic algorithm can do in the query model because if we have queried every string except one and found no solutions, we cannot be sure the final string is not a solution without querying it. Randomness can offer minor improvements, such as reducing the expected number of queries or trading correctness probability for query reduction, but the number of queries remains linear in .
Grover's algorithm is a quantum algorithm for search that requires only or queries. This represents a quadratic advantage over classical methods. While this advantage may not lead to practical application soon, it is a foundational part of quantum algorithms. The algorithm is often expressed using phase query gates.
Query Gates and Phase Query Operations
To understand Grover's algorithm, we must review query gates. The ordinary query gate for a function is defined on standard basis states by XORing the output value onto an additional qubit. From a Boolean circuit for , we can build a circuit for at a cost linear in the size of the Boolean circuit. On the other hand, the phase query gate operates on qubits instead of . It automatically kicks the function value into the phase: . By using phase kickback with a gate and a state, we can implement a gate at the cost of one evaluation of . While a gate alone cannot recover a gate, a controlled version of can be used to build a gate.
In addition to the phase query gate for , we require a phase query gate for the -bit OR function (). This function takes the value zero only for the all-zero string and one for all others. The gate does not depend on and therefore requires no queries. It can be built using a Boolean circuit that computes the OR function on bits.
Description of Grover's Algorithm
Grover's algorithm begins by initializing qubits to the state, creating an equal superposition of all binary strings of length . At this point, every string is equally likely to be a solution. We then repeatedly apply the Grover operation, denoted as , a total of times, where is a non-negative integer. Finally, we measure in the standard basis to obtain a candidate solution . While there is no guarantee is a solution, a good choice of makes the probability large. We can spend one additional query to check if is a solution. If it is not, we can try again or report no solutions.
The Grover operation is an -qubit operation composed of: a gate, a layer of Hadamard gates (), a gate, and another layer of Hadamard gates. One iteration of requires exactly one query to because only the portion depends on . Thus, the number of iterations equals the number of queries.
Analysis of the Grover Subspace
To analyze the algorithm, we partition the set of all -bit strings into two sets: containing strings that evaluate to zero (non-solutions) and containing strings that evaluate to one (solutions). We assume both sets are non-empty. Let be the uniform superposition over all non-solutions and be the uniform superposition over all solutions. The state of the register remains in the two-dimensional subspace spanned by and throughout the algorithm. The initial state (the uniform superposition of all strings) can be expressed as , where is the number of solutions.
By examining the action of on this subspace, we find it behaves as a rotation matrix . The action of on the subspace reflects the state about the line parallel to by putting a minus sign on the component of . The second part of the operation, , is a reflection about the line parallel to the uniform state . In geometry, the composition of two reflections is a rotation. Specifically, the Grover operation rotates the state by an angle of , where . After applications of , the state of the register is .
Choosing the Number of Iterations
The goal is to choose such that the probability of measuring a solution is large. This probability is given by . We want the angle to be as close to as possible. Solving for gives an ideal value of . Since must be an integer, we typically choose . This choice depends on the number of solutions .
In the case of unique search (), which was the version Lov Grover originaly introduced in 1996, the angle is approximately for large . The number of iterations is then approximately . For example, if , is approximately , and is . In this specific case, the probability of failure is only about %. For , it requires exactly one query and works perfectly. Generally, the success probability for unique search is at least .
If there are multiple solutions and we know , Grover's algorithm works with probability at least . For instance, if and , the optimal , yielding a success probability greater than %. Using a target meant for when would result in a very small probability of success because the state would rotate past the target vector. The query requirement is at most .
Searching with an Unknown Number of Solutions
If the number of solutions is unknown, we cannot calculate the exact optimal . A simple approach is to choose uniformly at random between and . This gives at least a % chance of finding a solution if one exists. We can boost this probability by repeating the process; for example, independent runs would provide a % success rate. This requires queries.
A more sophisticated approach starts with and repeatedly runs Grover's algorithm with a random number of iterations between and , increasing exponentially after each failure. A common rate of increase is replacing with the ceiling of . Doubling is too fast to benefit from lighter spins. This method ensures we find a solution in queries without knowing in advance. If no solutions exist, the process terminates after queries.
Optimality and Applications
Within the query model, Grover's algorithm is asymptotically optimal; it is impossible to solve the search problem using fewer than queries in the worst case. This fact was known even before Grover discovered his algorithm. The square root speedup is broadly applicable; Grover's algorithm can be used as a subroutine for other tasks, such as finding the minimum of a set of values with a quadratic advantage over classical algorithms. Furthermore, the technique of using two reflections can be generalized as amplitude amplification, which quadratically boosts the success probability of other quantum algorithms. While it may not provide a practical advantage immediately, Grover's algorithm remains a fundamental and versatile component of quantum computation.