Grover’s algorithm
Raffaele Solcà
Assistant: Dr. Alejandro Daleo
17.03.2008
Contents
1. Introduction
• Grover’s algorithm
• Elements of a quantum computer
2. The algorithm
• Abstraction of the problem
• Design of the algorithm
• Example with n=2
• Analysis of the steps of the algorithm
• Implementation with local transformations
3. Geometrical interpretation
• Geometrical understanding of the algorithm
• Number of steps necessary to find the solution
• Probability of failure
4. The case with t solutions
• Number of steps and probability of failure
2
1. Introduction
What is Grover’s algorithm?
• An Algorithm based on quantum computation.
• It provides a solution of the search problem.
Simple example of the search problem
• We have a phonebook and we are looking for a
person who has a specific phone number.
• With a classical algorithm we need O( N ) steps to find
the person.
• With Grover’s algorithm we need only O( N ) steps.
3
1. Introduction
A quantum computer operates on qubits…
• State of a qubit: ϕ =α 0 +β 1
… using quantum gates
• Unitary transformation
• They are reversible
• Can act on single or many qubits
Measurement of qubits
• The wavefunction collapses in one of the states.
ϕ = ∑ α i i → j with probability α j
2
4
1. Introduction
Some gates we will need:
Hadamard Gate
• Generate superposition
• Defined as: 1 1 1
H=
2 1 − 1
Walsh-Hadamard Gate
• Generalization of H for many qubits
• Equivalent to apply H on each qubit
γ 1 ⊗L ⊗ γ n H γ 1 ⊗L ⊗ H γ n
γ i ∈ {0,1}
• Matrix : Wij =
1
(− 1)i ⋅ j 5
N
1. Introduction
Oracle
• Is a quantum mechanical operator.
• It is defined as
• If the second register is initialized with
1
(0 − 1 )
2
it simply swaps the sign of the amplitude of the state
with f ( x ) = 1
6
2. The algorithm
The abstracted problem
• Define a function f : A → {0,1}
A is a set with N = 2 n elements
There is only an element s ∈ A with f (s ) = 1
• We are looking for the element x for which f (x ) = 1
7
2. The algorithm
Design of the algorithm
• The steps of the algorithm:
i. Initialization of first register in the
superposition state:
1 1 1 1
, , ,L,
N N N N
( )
ii. Repeat the following operation O N times:
a. Apply the oracle
1
b. Apply the diffusion matrix Dij = −δ ij + 2
N
iii. Measure the resulting state of first register.
8
2. The algorithm
Example with N=4 elements (n=2 qubits),
we assume that the solution is the state
2 = 10
• We will see that we only need to apply step ii. once.
• We need to know the number of iterations needed
because we will see that the probability does not
increase monotonically with them.
9
2. The algorithm
Apply the steps of Grover’s algorithm on
the example.
i. Initial state 1 1 1 1
, , ,
2 2 2 2
1 1 1 1
ii. a. Application of the oracle , ,− ,
2 2 2 2
ii. b. Application of D
1
Dij = −δ ij + 2 1 1 1 1 1 1 1 1
N − , ,− , + 2 , , , = (0,0,1,0 )
2 2 2 2 4 4 4 4
iii.Measurement 2 = 10
with probability p =1
10
2. The algorithm
Analysis of the steps.
i. Initialization of first register in the superposition state:
1 1 1 1
, , ,L,
N N N N
To reach this superposition we can initialize the first
register in the state (1,0, K ,0 ) and apply the Walsh-
Hadamard gate.
• For instance we apply the Walsh-Hadamard gate to the
n=2 initialized state ψ 0 = 0 0
ψ =W ψ0 =
1
( 0 + 1 )⊗ ( 0 + 1 ) = ∑ i
1 1 3
2 2 2 i =0
11
2. The algorithm
Analysis of the steps.
( )
ii. Repeat the following operation O N times:
a. Apply the oracle
1
b. Apply the diffusion matrix Dij = −δ ij + 2
N
a. The application of the oracle changes the sign of the
amplitude of the component for which f ( x ) = 1
b. We prove that D is unitary
• An example of an application of D
12
2. The algorithm
Implementation with local transformations
• A local transformation acts on single states.
• We implement the algorithm with local transformations
because these transformations can be implemented with
elementary quantum gates.
• We prove that D can be represented as a product of
local transformations:
1
Dij = −δ ij + 2 D = W (R1 − I )W
N where
R1, 00 = 2 and R1,ij = 0 for j or i ≠ 0
• W , (R1 − I ) are local transformations.
13
We have seen
• The search problem
• A classical solution
• A quantum mechanical solution: Grover’s algorithm
• How it is defined
• How it works: Example with n=2
We will see
• Geometrical interpretation
• An application of step ii.
• The number of iterations we need to find the
right answer
• The case with t solution
14
3. Geometrical interpretation
Why can we do a simple geometrical representation?
• All amplitudes are real
• The amplitudes of the non-searched states are equal
⇒ We can represent all the states of the algorithm as a
linear combination of :
• the state of the searched element s
• the linear combination of the other states
Why do we make a geometrical representation?
• Easy understanding of the algorithm
• Easy determination of the number of steps we have
to apply 15
3. Geometrical interpretation
Observation
• Define θ as sin (θ ) =
1
N
• Observe that the application of the oracle is a
reflection around the horizontal axis
16
3. Geometrical interpretation
Application of step ii. on a generic state
as in figure
17
3. Geometrical interpretation
The angle between the states before and
after the application of step ii.:
18
3. Geometrical interpretation
Determination of the steps needed to
approximate the solution
19
3. Geometrical interpretation
Determination of the number of
applications of step ii.
• After m applications of step ii. we have the state
• The probability of finding the searched state is
• If we want to have a probability of about 1 we have
to choose
(2m + 1)θ ≈ π ⇔ m ≈ π − 1
2 4θ 2
Clearly we need an integer number of iterations m
π
⇒ m≈ 20
4θ
3. Geometrical interpretation
1
For small θ (big N) θ ≈ sin θ =
N
π
• We can approximate m ≈ N
4
Probability of failure
• The probability of failure is given by
pu = cos 2 ((2m + 1)θ )
π
= sin 2 − (2m + 1) θ < sin 2 θ =
1
2 N
21
3. Geometrical interpretation
Example with n=2
• By definition: sin (θ ) =
1
⇒ θ = 30°
2
⇒ Only one application
22
3. Geometrical interpretation
Probability of success as a function of n
after applications of step ii.
23
4. The case with t solutions
Analyze the problem with t solutions
sin (θ ) =
t
• We define:
N
• After m applications of step ii. we have the state
ψ m = sin ((2m + 1)θ ) s + cos((2m + 1)θ ) u
π
• As for one solution we need m = steps
4θ
with a probability of failure
t
pu < sin 2 θ =
N 24
Summary
The search problem
• The classical solution
• A quantum mechanical solution: Grover’s algorithm
Grover’s algorithm
• How it is defined
• How it works: Example with n=2
Geometrical interpretation
• The effect of the application of step ii.
• How many step we have to apply
• What is the probability of failure / of finding the correct answer
The case with t solutions
• Drawback: in order to have high probability of success we have to
know the number t of solutions and t << N.
25