QAP Grover S Algorithm
QAP Grover S Algorithm
1/21
Search Algorithms
2/21
Grover’s Search Algorithm
3/21
Amplitude Amplification
⇒ Increase probability of observing correct answer by increasing
probability amplitude associated with answer ket → |answer ⟩
⇒ Decrease all other probabilities.
⇒ Example: Lets say we need to search |11⟩
1 1 1 1
|ψ⟩ = |00⟩ + |01⟩ + |10⟩ + |11⟩
2 2 2 2
Amplify |11⟩
√
1 1 1 3
|ψ⟩ = √ |00⟩ + √ |01⟩ + √ |10⟩ + |11⟩
12 12 12 2
⇒ Amplitude Amplification consists of two parts:
⇒ Oracle/Inversion : Assign −ve phase to chosen state
⇒ Diffuser/Reflection Operator : Amplify Amplitude of
selected(−ve) state and decrease amplitude of other
states.
4/21
Oracle/Inversion Operator
⇒ Initial State: |00⟩
⇒ Start with balanced superposition (using Hadamard Gate):
1 1 1 1 1 1 1 1
H|00⟩ = H|0⟩ ⊗ H|0⟩ = √ ⊗√
2 1 −1 0 2 1 −1 0
1 1 0 0 0
1 1 = 1 0 + 1 + 0 + 0
=
2 1 2 0 0 1 0
1 0 0 0 1
1 1 1 1
|ψ⟩ = |00⟩ + |01⟩ + |10⟩ + |11⟩
2 2 2 2
⇒ Next assign -1 to selected |ket⟩ → |11⟩
⇒ This can be done using combination of X, Z and CZ gates.
1 0 0 0
0 1 1 0 0 1 0 0
X = ,Z = and CZ =
1 0 0 −1 0 0 1 0
0 0 0 −1
5/21
Oracle/ Inversion Operator
⇒ CZ gate flips phase of if control bit is 1.
⇒ For |11⟩ we can use CZ gate. We will get:
1 1 1 1
|ψ⟩ = |00⟩ + |01⟩ + |10⟩ + |11⟩
2 2 2 2
1 0 0 0 1
1 0 1 0 0
1
=
2 0 0 1 0 1
0 0 0 −1 1
1 1 0 0 0
1 1 1 0 1 0 0
= = + + +
2 1 2 0 0 1 0
−1 0 0 0 −1
1 1 1 1
= |00⟩ + |01⟩ + |10⟩ − |11⟩
2 2 2 2
⇒ Amplitude of states: (0.5, 0.5, 0.5, −0.5), Mean = 0.25
7/21
Oracle/Inversion Operator
(a) Oracle for |00⟩ (b) Oracle for |01⟩ (c) Oracle for |10⟩
Since the states are in superposition Two qubits are considered as together not individuals
1
Z |ψ⟩ = Z (|00⟩ + |01⟩ + |10⟩ + |11⟩)
2
1
= Z (|00⟩ − |01⟩ + |10⟩ − |11⟩) → Please refer next slide for explanation
2
1
CZ |ψ⟩ = CZ (|00⟩ − |01⟩ + |10⟩ − |11⟩)
2
1
= (|00⟩ − |01⟩ + |10⟩ + |11⟩)
2
8/21
Z gate
Z gate on a single qubit
1 0 1 1
Z |0⟩ = = = |0⟩
0 −1 0 0
1 0 0 0
Z |1⟩ = = = −|1⟩
0 −1 1 −1
1 0 0 0 1 1
1 0 1 0 0 −1 0 0
0
0
Z |00⟩ = (Z ⊗ I )|00⟩ = ⊗ |00⟩ = 0 = |00⟩
=
0 −1 0 1 0 0 1 0 0
0 0 0 −1 0 0
1 0 0 0 0 0
1 0 1 0 0 −1 0 0
1
−1
Z |01⟩ = (Z ⊗ I )|01⟩ = ⊗ |01⟩ = 0 = −|01⟩
=
0 −1 0 1 0 0 1 0 0
0 0 0 −1 0 0
1 0 0 0 0 0
1 0 1 0 0 −1 0 0
0
0
Z |10⟩ = (Z ⊗ I )|10⟩ = ⊗ |10⟩ = 1 = |10⟩
=
0 −1 0 1 0 0 1 0 1
0 0 0 −1 0 0
1 0 0 0 0 0
1 0 1 0 0 −1 0 0
0
0
Z |11⟩ = (Z ⊗ I )|11⟩ = ⊗ |11⟩ = 0 = −|11⟩
=
0 −1 0 1 0 0 1 0 0
0 0 0 −1 1 −1
9/21
Diffuser/Reflection Operator
10/21
Diffuser/Reflection Operator And Circuit for example.
11/21
Diffuser/Reflection Operator
Hadamard Gate:
1
H|ψ⟩ = H(|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
1
= ((H ⊗ H)|00⟩ + (H ⊗ H)|01⟩ + (H ⊗ H)|10⟩ − (H ⊗ H)|11⟩)
2
1 1 1 1 1 1
(H ⊗ H)|00⟩ = √ ⊗√ ] [|0⟩ ⊗ |0⟩]
2 1 −1 2 1 −1
1 1 1 1 1 1
1 1 −1 1 −1 0 1 1
= =
2 1 1 −1 −1 0 2 1
1 −1 −1 1 0 1
1
= (|00⟩ + |01⟩ + |10⟩ + |11⟩)
2
1
H|01⟩ = (|00⟩ − |01⟩ + |10⟩ − |11⟩)
2
1
H|10⟩ = (|00⟩ + |01⟩ − |10⟩ − |11⟩)
2
1
H|11⟩ = (|00⟩ − |01⟩ − |10⟩ + |11⟩)
2
1
H|ψ⟩ = (|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
12/21
Diffuser/Reflection Operator
X Gate:
1
X |ψ⟩ = X (|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
0 1 0 1
X |00⟩ = ⊗ [|0⟩ ⊗ |0⟩]
1 0 1 0
0 0 0 1 1 0
0 0 1 0 0 0
X |00⟩ =
= = |11⟩
0 1 0 0 0 0
1 0 0 0 0 1
X |01⟩ = X |10⟩, X |10⟩ = X |01⟩, X |11⟩ = X |00⟩
1
X |ψ⟩ = (−|00⟩ + |01⟩ + |10⟩ + |11⟩)
2
CZ Gate:
1
CZ |ψ⟩ = CZ (−|00⟩ + |01⟩ + |10⟩ + |11⟩)
2
1 0 0 0 −1 −1
1 0 1 0 1 = 1 1
0
=
2 0 0 1 0 1 2 1
0 0 0 −1 1 −1
1
CZ |ψ⟩ = (−|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
13/21
Diffuser/Reflection Operator
X Gate:
1
X |ψ⟩ = X (−|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
1
X |ψ⟩ = (−|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
Hadamard Gate:
1
H|ψ⟩ = H(−|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
1
H(−|00⟩) = (−|00⟩ − |01⟩ − |10⟩ − |11⟩)
2
1
H|01⟩ = (|00⟩ − |01⟩ + |10⟩ − |11⟩)
2
1
H|10⟩ = (|00⟩ + |01⟩ − |10⟩ − |11⟩)
2
1
H(−|11⟩) = (−|00⟩ + |01⟩ + |10⟩ − |11⟩)
2
H|ψ⟩ = |11⟩
14/21
Grover’s Algorithm for 3 Qubits
H|ψ⟩ = (H ⊗ H ⊗ H)
1 1 1 1 1 1 1 1
1 −1 1 −1 1 1 −1 1
1 1 −1 1 1 1 −1 −1
HH HH 1 −1 −1 1 1 −1 −1 1
H= = (0.354)
HH −HH 1 1 1 1 −1 −1 −1 −1
1 −1 1 −1 −1 1 −1 1
1 1 −1 −1 −1 −1 1 1
1 −1 −1 1 −1 1 1 −1
1 1 1 1 1 1 1 1 1 1
1 −1 1 −1 1 1 −1 1 0 1
1 1 −1 1 1 1 −1 −1 0 1
1 −1 −1 1 1 −1 −1 1 0 1
H|0001⟩ = (0.354) = (0.354)
1 1 1 1 −1 −1 −1 −1 0 1
1 −1 1 −1 −1 1 −1 1 0 1
1 1 −1 −1 −1 −1 1 1 0 1
1 −1 −1 1 −1 1 1 −1 0 1
= (0.354)(|000⟩ + |001⟩ + |010⟩ + |011⟩ + |100⟩ + |101⟩ + |110⟩ + |111⟩)
16/21
Grover’s Algorithm for 3 Qubits
Oracle/Inversion Operator:
CCZ |ψ⟩ = (0.354)CCZ (|000⟩ + |001⟩ + |010⟩ + |011⟩ + |100⟩ + |101⟩ + |110⟩ + |111⟩)
= (0.354)(|000⟩ + |001⟩ + |010⟩ + |011⟩ + |100⟩ + |101⟩ + |110⟩ − |111⟩)
17/21
Grover’s Algorithm for 3 Qubits - Diffuser
H Gate:
X Gate:
CCZ Gate:
18/21
Grover’s Algorithm for 3 Qubits - Diffuser
X Gate:
H Gate:
20/21
Thank You
21/21