Choosing the number of iterations
דף זה טרם תורגם. התוכן מוצג באנגלית.
We have established that the state vector of the register in Grover's algorithm remains in the two-dimensional subspace spanned by and once the initialization step has been performed.
The goal is to find an element and this goal will be accomplished if we can obtain the state — for if we measure this state, we're guaranteed to get a measurement outcome Given that the state of after iterations in step 2 is
we should choose so that
is as close to as possible in absolute value, to maximize the probability to obtain from the measurement. For any angle the value oscillates as increases, though it is not necessarily periodic — there's no guarantee that we'll ever get the same value twice.
Naturally, in addition to making the probability of obtaining an element from the measurement large, we would also like to choose to be as small as possible, because applications of the operation requires queries to the function Because we're aiming to make close to in absolute value, a natural way to do this is to choose so that
Solving for yields
Of course, must be an integer, so we won't necessarily be able to hit this value exactly — but what we can do is to take the closest integer to this value, which is
This is the recommended number of iterations for Grover's algorithm. As we proceed with the analysis, we'll see that the closeness of this integer to the target value naturally affects the performance of the algorithm.
(As an aside, if the target value happens to be exactly half-way between two integers, this expression of is what we get by rounding up. We could alternatively round down, which makes sense to do because it means one fewer query — but this is secondary and unimportant for the sake of the lesson.)
Recalling that the value of the angle is given by the formula
we see that the recommended number of iterations depends on the number of strings in This presents a challenge if we don't know how many solutions we have, as we'll discuss later.
Unique search
First, let's focus on the situation in which there's a single string such that Another way to say this is that we're considering an instance of the Unique search problem. In this case we have
which can be conveniently approximated as
when gets large. If we substitute into the expression
we obtain