Grover Algorithm Notes.
Grover Algorithm Notes.
Grover's algorithm, proposed by Lov Grover in 1996, is a quantum algorithm for searching
an unsorted database, offering a quadratic speedup compared to classical algorithms.
Grover’s algorithm is a quantum algorithm that solves the unstructured search problem. In an
unstructured search problem, we are given a set of N elements and we want to find a single
marked element. A classical computer would need to search through all N elements in order
to find the marked element, which would take time O(N). Grover’s algorithm, on the other
hand, can find the marked element in time O(√ N).
Algorithm:
The algorithm works by applying a series of quantum operations to the input state, which is
initialized as a superposition of all possible search states. The key idea behind Grover’s
algorithm is to amplify the amplitude of the marked state (i.e., the state containing the item
that we are searching for) by iteratively applying a quantum operation known as the Grover
operator.
2. Oracle: Apply an oracle gate, which marks the solution(s) in the superposition. This
oracle flips the sign of the amplitude of the solution state(s).
3. Amplitude Amplification: Apply a series of operations involving the oracle and a
diffuser gate. This step amplifies the amplitude of the solution state(s) while
decreasing the amplitude of the other states. It involves applying the oracle, followed
by a reflection operation about the mean amplitude, achieved by the diffuser gate.
4. Repeat: Steps 2 and 3 are repeated a certain number of times (roughly √N times) to
increase the probability of measuring the solution(s) state.
5. Measurement: Finally, measure the quantum state. The solution(s) will be obtained
with a higher probability compared to the other states.
By repeating the steps of oracle and amplitude amplification, Grover's algorithm can increase
the probability of measuring the correct solution, achieving a quadratic speedup compared to
classical algorithms.
Pseudo Code:
Input: N: number of items in the list, oracle(x): a function that returns true if x is the target
item, and false otherwise
Step 1: Initialize state
Hadamard transform on all qubits
Step 2: Iterate over Grover’s algorithm
for k = 1 to sqrt(N) do
# Step 2a: Apply the oracle
Apply the oracle to the state
# Step 2b: Apply the diffusion operator
Hadamard transform on all qubits
Apply an X gate on all qubits
Apply a multi-controlled Z gate (which flips the sign of the state only if all
qubits are in the state |1>)
Apply an X gate on all qubits
Hadamard transform on all qubits
end for
Step 3: Measure the state and output the result
Measure the state and output the result
# Number of qubits
n=3
*************************************************************