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}`

, there exists ฯ (a name) in the domain, such that ^{n} โ {0,1}^{n}`f(ฯ) = a`

, where a is the phone number. Having `f(ฯ)`

defined, we could further define another function `f`

, which maps n-bit integer to 1 bit:_{ฯ}(x) = ฮด_{x=ฯ}

`f`_{ฯ}(x โ ฯ) = 0
f_{ฯ}(x = ฯ) = 1

In quantum computing, the function `f`

is defined as an operator _{ฯ}`U`

as usual:_{f}

`U`_{f}|xโฉ|yโฉ = |xโฉ|y โ f_{ฯ}(x)โฉ

If we pass through the `|yโฉ`

register the Hadamard `|-โฉ`

, we have this express as usual:

`U`_{f} 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`

, which works like below:_{ฯ}|xโฉ = (-1)^{fฯ(x)} |xโฉ

`โ |xโฉ โ |ฯโฉ U`_{ฯ}|xโฉ = |xโฉ
โ |xโฉ = |ฯโฉ U_{ฯ}|ฯโฉ = -|ฯโฉ

Actually, the `U`

operator can be rewritten like this:_{ฯ}|xโฉ

`U`_{ฯ}|xโฉ = I - 2|ฯโฉโจฯ|

The input data of the Grover’s algorithm is `|sโฉ = H|0โฉ`

, here we can define another useful operator:^{n} = 1/2^{n/2} ฮฃ^{2^n-1}_{x=0} |xโฉ

`U`_{s} = 2|sโฉโจs| - I

Each iteration of the Grover’s algorithm is: `R`

. After applying k iterations on initial state _{grov} = U_{s} U_{ฯ}`|sโฉ`

, we have something like this: `(U`

._{s} U_{ฯ})^{k} |sโฉ

`|ฯโฉ`

is a vector in the space with dimensionality N. `|sโฉ = 1/โN โ`

. The sine of the angle ฮธ between ^{Nโ1}_{x=0} |xโฉ`|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 `ฯ`

, such that _{i}`f`

, 1 โค i โค k . The algorithm does not change, but we have k vectors, and angle _{ฯ}(ฯ_{i}) = 1`ฮธ`

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 `U`

is because it reflect in the desired direction. _{s}`|sโฉ`

is the only thing we know in this space, i.e. the equally weighted sum of all basis vectors.

### Optimality

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

- The target is
`|ฯโฉ`

. - There exist, in general, some operator better:
`U(ฯ,t) = U`

. Here U_{t}U_{ฯ}U_{t-1}U_{ฯ}...U_{1}U_{ฯ}_{t}is the generalization of U_{s}in Grover’s algorithm. `|ฯ`

is the initial state._{0}โฉ`|ฯ`

_{t}โฉ = U(ฯ,t)|ฯ_{0}โฉ- T is defined as
`U(ฯ,t)|ฯ`

_{0}โฉ = |ฯ_{T}โฉ = |ฯ_{ฯ}โฉ โ |ฯโฉ - We are going to find some vector
`|ฯโฉ`

for which this double inequality is true:

`4T`^{2} โฅ โ^{N-1}_{ฯ=0} || |ฯ_{ฯ}โฉ - |ฯโฉ ||^{2} โฅ 2N - 2โN
โน 4T^{2} โฅ 2N - 2โN
โน T โ โN/โ2

Compare the T with that of Grover’s algorithm (`T`

). The most effective algorithm is not very much better than that of Grover’s._{grov} = (ฯ/4)โN

## 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}`

, and for any such functions, we could introduce the value ^{n} โ {0,1}`x = x`

, which is a very long bit string._{N-1}x_{N-2}...x_{0}, N = 2^{n}

Function Parity() maps functions to 1 bit. First each bit `x`

is used to calculate _{i}`x`

, then parity is calculated:^{~}_{i}

`x`^{~}_{i} = 1 - 2x_{i}
Parity(x^{~}) = โ^{N-1}_{i=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}`

, 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.^{n} โ {0,1}

## 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!

Tweet