CSE 599d - Quantum Computing Grover's Algorithm: Department of Computer Science & Engineering, University of Washington
CSE 599d - Quantum Computing Grover's Algorithm: Department of Computer Science & Engineering, University of Washington
CSE 599d - Quantum Computing Grover's Algorithm: Department of Computer Science & Engineering, University of Washington
Grover’s Algorithm
Dave Bacon
Department of Computer Science & Engineering, University of Washington
After Peter Shor demonstrated that quantum computers could efficiently factor, great interest arose in finding
other problems for which quantum algorithms could outperform the best known classical algorithms. One of the early
offshoots of this work was an algorithm invented by Lov Grover in 1996. Here we will describe Grover’s algorithm
and show that it is, in a query complexity manner, the optimal quantum algorithm.
I. GROVER’S ALGORITHM
Suppose that we have a function f (x) from {0, 1}n to {0, 1} which is zero on all inputs except for a single (marked)
item x0 : f (x) = δx,x0 . By querying this function you wish to find the marked item x0 . This is like finding a needle
in a haystack. Certainly if you have no information about the particular x0 , then finding this marked item is very
difficult. In the worst case it will take 2n − 1 queries to find x0 for a deterministic algorithm. Well what if we turn
this haystack into a quantum haystack? This is the question that Grover asked.
In the quantum version of Grover’s problem we have access to a function which computes f (x) in our standard
reversible manner:
X
Uf = |xihx| ⊗ |y ⊕ f (x)ihy|. (1)
x,y∈{0,1}n
Using our standard trick of phase kickback, we can feed |−i = √12 (|0i − |1i) into the y register of this unitary. If we
do this, then the effect on the first register is still unitary and is given by
X X
Vf = (−1)f (x) |xihx| = (−1)δx,x0 |xihx| (2)
x∈{0,1}n x∈{0,1}n
We note that
r
2n − 1 0 1
|ψi = |ψ i + √ |x0 i. (4)
2n 2n
Now notice that Vf preserve the subspace |x0 i, |ψ 0 i:
Vf |x0 i = −|x0 i
Vf |ψ 0 i = |ψ 0 i. (5)
Now consider the unitary W = 2|ψihψ| − I. This is unitary? Yes because (2|ψihψ| − I)(2|ψihψ| − I)† = 4|ψihψ| −
2|ψihψ| − 2|ψihψ| + I = I. W also preserves the subspace spanned by |x0 i and |ψi:
p
2 (2n − 1) 0
2 2
W |x0 i = (2|ψihψ| − I)|x0 i = √ |ψi − |x0 i = |ψ i + − 1 |x0 i
2n 2n 2n
r √
2n − 1 2(2n − 1) 2 2n − 1
W |ψ 0 i = (2|ψihψ| − I)|ψ 0 i = 2 |ψi − |ψ 0
i = − 1 |ψ 0
i + |x0 i
2n 2n 2n
√
2 2n − 1
2 0
= − − 1 |ψ i + |x0 i (6)
2n 2n
2
So we have seen that Grover’s algorithm offers a speedup which is quadratic in finding the needle in the haystack.
A good question to ask is whether we could have done any better. There is a distinct way in which we could not have
done better and that is if we require ourselves to query f in the manner we have described then Grover’s algorithm
is optimal. Let’s prove this.
Suppose we start our attempt to determine f by starting in the state |ψi. Now we apply a sequence of oracle calls
followed by arbitrary (but independent of the oracles) unitaries. Suppose the oracle we use is the phase-kicked back
oracle
Notice that Vf depends on x0 . If we hadn’t called the oracle, we would be in the state
This setup is the most general setup for querying the oracle. We want to show that when we do this it is impossible
to make the |φkx0 i orthogonal enough such that a measurement can distinguish these different states (for different x0
values) unless we make k big enough (i.e the number of queries is high enough.) We do this by showing that we need
k large to make
X
rk = |||φkx0 i − |φk i||2 (17)
x0 ∈{0,1}n
is small unless k is large enough. Then we will show that this implies that when this quantity is small there is no way
to identify the x0 with high probability. Why do we choose |φk i? Well this is the state that would exist if no oracle
calls were made, so measuring our distance from this state is measuring how much effect the oracle is having.
So first we want to bound rk . To do this we show that rk ≤ 4k 2 . This is clearly true for k = 0. We proceed
inductively. First we use the fact that Uk+1 is unitary:
|||φk+1
x0 i − |φ
k+1 2
i|| = ||Uk+1 Vf |φkx0 i − Uk+1 |φk i||2 = ||Vf |φkx0 i − |φk i||2 (18)
The fact that this expression is equal is a consequence of the fact that the |φkx0 i and |φk i states cannot be made more
orthogonal by a unitary rotation. The only operator which can make them more orthogonal is Vf . Now we reexpress
this as
|||φk+1
x0 i − |φ
k+1 2
i|| = ||Vf (|φkx0 i − |φk i) + (Vf − I)|φk i||2 (19)
Next use the inequality |||ai + |bi||2 ≤ |||ai||2 + |||bi||2 + 2|||ai|| |||bi|| to obtain
|||φk+1
x0 i − |φ
k+1 2
i|| ≤ ||Vf (|φkx0 i − |φk i)||2 + ||(Vf − I)|φk i||2 + 2||Vf (|φkx0 i − |φk i)|| ||(Vf − I)|φk i|| (20)
Since Vf is unitary,
|||φk+1
x0 i − |φ
k+1 2
i|| ≤ ||(|φkx0 i − |φk i)||2 + ||(Vf − I)|φk i||2 + 2||(|φkx0 i − |φk i)|| ||(Vf − I)|φk i|| (21)
|||φk+1
x0 i − |φ
k+1 2
i|| ≤ ||(|φkx0 i − |φk i)||2 + || − 2|x0 ihx0 ||φk i||2 + 2||(|φkx0 i − |φk i)|| || − 2|x0 ihx0 |φk i|| (22)
or
|||φk+1
x0 i − |φ
k+1 2
i|| ≤ ||(|φkx0 i − |φk i)||2 + 4||hx0 |φk i|x0 i||2 + 4||(|φkx0 i − |φk i)|| ||hx0 |φk i|x0 i|| (23)
or
X
rk+1 ≤ rk + 4 + 4||(|φkx0 i − |φk i)|| |hx0 |φk i| (26)
x0 ∈{0,1}n
or
√
rk+1 ≤ rk + 4 + 4 rk (29)
Now from our inductive hypothesis rk ≤ 4k 2 , so rk+1 ≤ 4k 2 + 4 + 42k = 4(k 2 + 2k + 1) = 4(k + 1)2 . Thus we have
showed that rk ≤ 4k 2 for all k.
The next part of the proof is to show that if rk is small then we cannot distinguish the different vectors |φkx0 i with high
probability. Suppose that we wish to identify x0 with probability greater than one half. Then, without loss of generality
assume that the basis we use to make this distinction is the computational basis. In order for this to succeed we require
that |hx0 |φkx0 i|2 ≥ 12 . This in turn implies that |||φkx0 i − |x0 i||2 = (hφkx0 |−ix0 |)(|φkx0 i − |x0 i) = 2 − hφkx0 |x0 i − hx0 |φkx0 i.
We can always adjust the global phase of the computational basis states to make the last two terms sum to a real
number and our bound on probability then yields
√
|||φkx0 i − |x0 i||2 ≤ 2 − 2 (30)
Now we want to show that if this is true that rk must be large. So we do the obvious and stick in one of those |x0 i
states into our expression for rk :
X
rk = |||φkx0 i − |x0 i + |x0 i − |φk i||2 (31)
x0 ∈{0,1}n
which is bounded by
X k
|||φx0 i − |x0 i||2 + |||φk i − |x0 i||2 − 2|||φkx0 i − |x0 i|| |||φk i − |x0 i||
rk ≥ (32)
x0 ∈{0,1}n
Thus
21 12 2
X X
rk ≥ − |||φkx0 i − |x0 i||2 + |||φk i − |x0 i||2 (34)
x0 ∈{0,1}n x0 ∈{0,1}n
5
Cauchy-Schwarz yields
2
X X X
|hx|φk i| ≤ 1 |hx|φk i|2 = 2n (37)
x∈{0,1}n x∈{0,1}n x∈{0,1}n
Thus we find
X √
|||φk i − |x0 i||2 ≥ 2(2n − 2n ) (38)
x0 ∈{0,1}n
So far I have worked with a function which maps {0, 1}n → {0, 1} and has only one marked item. But more
generally we can design our Grovers algorithm to work with a function {0, 1, . . . , N − 1} → {0, 1} which is 0 on N − M
on this domain and is 1 on the rest of the M points of this domain. The goal then will be to find a single one of the
inputs x such that f (x) = 1. For now we will assume that we know M . Let S be the set of x such that f (x) = 1.
Then we can define the states
1 X
|x0 i = √ |xi (41)
M x∈S
and
1 X
|φ0 = √ |xi (42)
N − M x∈S
/
and again produce a Grover’s iterate which rotates on this space. The argument is nearly identical, so I will not
repeat it. The important point, though, is that the state will rotate by an angle satisfying
p
2 M (N − M )
sin θ = (43)
N
6