Grover's Algorithm

Brute-force is apparently applicable to any problem of NP, since if you have some candidate for an answer, you can easily check / verify this candidate (but finding a candidate is still hard).

For example: given a phone number to find its owner in the phone book, you can easily check it, but you need n/2 time to find it on average. Another example is the traveling salesperson problem, where you don’t have the path but only desired length, finding the path is complicated, in the worst case you need n! time where n is the number of vertices.



For any problem that is solvable by brute-force search, if you can speed up the brute-force search with a quantum computer, you can make the process more effective. Lov Grover dealt with quantum algorithm which is able to solve any problem of NP, independent of its structure.

Grover’s Algorithm

Consider the phone book problem, where owners’ names are arranged in alphabetized order, it is easy to find the phone number given a name. This could be formalized as a function f: {0,1}n โ†’ {0,1}n, there exists ฯ‰ (a name) in the domain, such that f(ฯ‰) = a, where a is the phone number. Having f(ฯ‰) defined, we could further define another function fฯ‰(x) = ฮดx=ฯ‰, which maps n-bit integer to 1 bit:

fฯ‰(x โ‰  ฯ‰) = 0
fฯ‰(x = ฯ‰) = 1

In quantum computing, the function fฯ‰ is defined as an operator Uf as usual:

Uf|xโŸฉ|yโŸฉ = |xโŸฉ|y โŠ• fฯ‰(x)โŸฉ

If we pass through the |yโŸฉ register the Hadamard |-โŸฉ, we have this express as usual:

Uf 1/โˆš2 |xโŸฉ(|0โŸฉ-|1โŸฉ)
= 1/โˆš2 |xโŸฉ(|0 โŠ• fฯ‰(x)โŸฉ - |1 โŠ• fฯ‰(x)โŸฉ)
= 1/โˆš2 (-1)fฯ‰(x) |xโŸฉ(|0โŸฉ - |1โŸฉ)

We only consider the projection Uฯ‰|xโŸฉ = (-1)fฯ‰(x) |xโŸฉ, which works like below:

โˆ€ |xโŸฉ โ‰  |ฯ‰โŸฉ Uฯ‰|xโŸฉ = |xโŸฉ
โˆ€ |xโŸฉ = |ฯ‰โŸฉ Uฯ‰|ฯ‰โŸฉ = -|ฯ‰โŸฉ

Actually, the Uฯ‰|xโŸฉ operator can be rewritten like this:

Uฯ‰|xโŸฉ = I - 2|ฯ‰โŸฉโŸจฯ‰|

The input data of the Grover’s algorithm is |sโŸฉ = H|0โŸฉn = 1/2n/2 ฮฃ2^n-1x=0 |xโŸฉ, here we can define another useful operator:

Us = 2|sโŸฉโŸจs| - I

Each iteration of the Grover’s algorithm is: Rgrov = Us Uฯ‰. After applying k iterations on initial state |sโŸฉ, we have something like this: (Us Uฯ‰)k |sโŸฉ.

|ฯ‰โŸฉ is a vector in the space with dimensionality N. |sโŸฉ = 1/โˆšN โˆ‘Nโˆ’1x=0 |xโŸฉ. The sine of the angle ฮธ between |sโŸฉ and the hyperplane which is orthogonal to |ฯ‰โŸฉ, is sin(ฮธ) = 1/โˆšN.

Each iteration of Grover’s algorithm makes us closer to the state |ฯ‰โŸฉ with each step 2ฮธ. Suppose we have made T iterations, T โ‰ˆ (ฯ€/4)โˆšN. The time need to find a solution is O(โˆšN).



Why we choose the vector |sโŸฉ as an initial state? |sโŸฉ has equal angles to all the basis vectors of the space. We don’t know anything about |ฯ‰โŸฉ, but we must know ฮธ.

When there are multiple ฯ‰i, such that fฯ‰(ฯ‰i) = 1, 1 โ‰ค i โ‰ค k . The algorithm does not change, but we have k vectors, and angle ฮธ becomes greater. The sine of the angle ฮธ between |sโŸฉ and the hyperplane which is orthogonal to all vectors |ฯ‰iโŸฉ, is now sin(ฮธ) = โˆšk/โˆšN. And T โ‰ˆ (ฯ€/4)*(โˆšN/โˆšk).

Note that to use Grover’s algorithm, we must know the number of special points k to calculate the number of iterations T. Grover’s algorithm does not tolerate extra work. If you do more iterations than it’s needed, we may pass this point of interest.

The reason we choose operator Us is because it reflect in the desired direction. |sโŸฉ is the only thing we know in this space, i.e. the equally weighted sum of all basis vectors.

Grover's Algorithm, iteration

Optimality

Lov Grover proved that there is no better algorithm than Grover’s algorithm. Suppose:

  1. The target is |ฯ‰โŸฉ.
  2. There exist, in general, some operator better: U(ฯ‰,t) = UtUฯ‰Ut-1Uฯ‰...U1Uฯ‰. Here Ut is the generalization of Us in Grover’s algorithm.
  3. |ฯˆ0โŸฉ is the initial state.
  4. |ฯˆtโŸฉ = U(ฯ‰,t)|ฯˆ0โŸฉ
  5. T is defined as U(ฯ‰,t)|ฯˆ0โŸฉ = |ฯˆTโŸฉ = |ฯˆฯ‰โŸฉ โ‰ˆ |ฯ‰โŸฉ
  6. We are going to find some vector |ฯ•โŸฉ for which this double inequality is true:
4T2 โ‰ฅ โˆ‘N-1ฯ‰=0 || |ฯˆฯ‰โŸฉ - |ฯ†โŸฉ ||2 โ‰ฅ 2N - 2โˆšN
โŸน 4T2 โ‰ฅ 2N - 2โˆšN
โŸน T โ‰ˆ โˆšN/โˆš2

Compare the T with that of Grover’s algorithm (Tgrov = (ฯ€/4)โˆšN). The most effective algorithm is not very much better than that of Grover’s.

Quantum Computers aren’t Always Better

Quantum computers are not always better than classical ones. There are problems on which the quantum computers are almost as ineffective as classical ones.

Let’s consider all the functions of type f(x): {0,1}n โ†’ {0,1}, and for any such functions, we could introduce the value x = xN-1xN-2...x0, N = 2n, which is a very long bit string.

Function Parity() maps functions to 1 bit. First each bit xi is used to calculate x~i, then parity is calculated:

x~i = 1 - 2xi
Parity(x~) = โˆN-1i=0 x~i

If there are even numbers of 1 in x, the parity is 1; if there is odd number of 1 in x, the parity is -1.

To calculate the parity of a function of type f(x): {0,1}n โ†’ {0,1}, in classical computing, we have to try all the function values and multiply them. However quantum computer can not outperform classical ones on this task.



My Certificate

For more on Grover’s Algorithm, please refer to the wonderful course here https://www.coursera.org/learn/quantum-computing-algorithms


Related Quick Recap


I am Kesler Zhu, thank you for visiting my website. Check out more course reviews at https://KZHU.ai

All of your support will be used for maintenance of this site and more great content. I am humbled and grateful for your generosity. Thank you!




Don't forget to sign up newsletter, don't miss any chance to learn.

Or share what you've learned with friends!

Leave a Reply

Your email address will not be published. Required fields are marked *