Grover's algorithm explained

In quantum computing, Grover's algorithm, also known as the quantum search algorithm, is a quantum algorithm for unstructured search that finds with high probability the unique input to a black box function that produces a particular output value, using just

O(\sqrt{N})

evaluations of the function, where

N

is the size of the function's domain. It was devised by Lov Grover in 1996.[1]

The analogous problem in classical computation cannot be solved in fewer than

O(N)

evaluations (because, on average, one has to check half of the domain to get a 50% chance of finding the right input). Charles H. Bennett, Ethan Bernstein, Gilles Brassard, and Umesh Vazirani proved that any quantum solution to the problem needs to evaluate the function

\Omega(\sqrt{N})

times, so Grover's algorithm is asymptotically optimal.[2] Since classical algorithms for NP-complete problems require exponentially many steps, and Grover's algorithm provides at most a quadratic speedup over the classical solution for unstructured search, this suggests that Grover's algorithm by itself will not provide polynomial-time solutions for NP-complete problems (as the square root of an exponential function is an exponential, not polynomial, function).[3]

Unlike other quantum algorithms, which may provide exponential speedup over their classical counterparts, Grover's algorithm provides only a quadratic speedup. However, even quadratic speedup is considerable when

N

is large, and Grover's algorithm can be applied to speed up broad classes of algorithms.[3] Grover's algorithm could brute-force a 128-bit symmetric cryptographic key in roughly 264 iterations, or a 256-bit key in roughly 2128 iterations. It may not be the case that Grover's algorithm poses a significantly increased risk to encryption over existing classical algorithms, however.[4]

Applications and limitations

Grover's algorithm, along with variants like amplitude amplification, can be used to speed up a broad range of algorithms.[5] [6] [7] In particular, algorithms for NP-complete problems which contain exhaustive search as a subroutine can be sped up by Grover's algorithm. The current theoretical best algorithm, in terms of worst-case complexity, for 3SAT is one such example. Generic constraint satisfaction problems also see quadratic speedups with Grover.[8] These algorithms do not require that the input be given in the form of an oracle, since Grover's algorithm is being applied with an explicit function, e.g. the function checking that a set of bits satisfies a 3SAT instance. However, it is unclear whether Grover's algorithm could speed up best practical algorithms for these problems.

Grover's algorithm can also give provable speedups for black-box problems in quantum query complexity, including element distinctness[9] and the collision problem[10] (solved with the Brassard–Høyer–Tapp algorithm). In these types of problems, one treats the oracle function f as a database, and the goal is to use the quantum query to this function as few times as possible.

Cryptography

Grover's algorithm essentially solves the task of function inversion. Roughly speaking, if we have a function

y=f(x)

that can be evaluated on a quantum computer, Grover's algorithm allows us to calculate

x

when given

y

. Consequently, Grover's algorithm gives broad asymptotic speed-ups to many kinds of brute-force attacks on symmetric-key cryptography, including collision attacks and pre-image attacks.[11] However, this may not necessarily be the most efficient algorithm since, for example, the parallel rho algorithm is able to find a collision in SHA2 more efficiently than Grover's algorithm.[12]

Limitations

Grover's original paper described the algorithm as a database search algorithm, and this description is still common. The database in this analogy is a table of all of the function's outputs, indexed by the corresponding input. However, this database is not represented explicitly. Instead, an oracle is invoked to evaluate an item by its index. Reading a full database item by item and converting it into such a representation may take a lot longer than Grover's search. To account for such effects, Grover's algorithm can be viewed as solving an equation or satisfying a constraint. In such applications, the oracle is a way to check the constraint and is not related to the search algorithm. This separation usually prevents algorithmic optimizations, whereas conventional search algorithms often rely on such optimizations and avoid exhaustive search. Fortunately, fast Grover's oracle implementation is possible for many constraint satisfaction and optimization problems.[13]

The major barrier to instantiating a speedup from Grover's algorithm is that the quadratic speedup achieved is too modest to overcome the large overhead of near-term quantum computers.[14] However, later generations of fault-tolerant quantum computers with better hardware performance may be able to realize these speedups for practical instances of data.

Problem description

As input for Grover's algorithm, suppose we have a function

f\colon\{0,1,\ldots,N-1\}\to\{0,1\}

. In the "unstructured database" analogy, the domain represent indices to a database, and if and only if the data that x points to satisfies the search criterion. We additionally assume that only one index satisfies, and we call this index ω. Our goal is to identify ω.

We can access f with a subroutine (sometimes called an oracle) in the form of a unitary operator Uω that acts as follows:

\begin{cases} U\omega|x\rang=-|x\rang&forx=\omega,thatis,f(x)=1,\\ U\omega|x\rang=|x\rang&forx\ne\omega,thatis,f(x)=0. \end{cases}

This uses the

N

-dimensional state space

l{H}

, which is supplied by a register with

n=\lceillog2N\rceil

qubits.This is often written as

U\omega|x\rang=(-1)f(x)|x\rang.

Grover's algorithm outputs ω with probability at least 1/2 using

O(\sqrt{N})

applications of Uω. This probability can be made arbitrarily large by running Grover's algorithm multiple times. If one runs Grover's algorithm until ω is found, the expected number of applications is still

O(\sqrt{N})

, since it will only be run twice on average.

Alternative oracle definition

This section compares the above oracle

U\omega

with an oracle

Uf

.

Uω is different from the standard quantum oracle for a function f. This standard oracle, denoted here as Uf, uses an ancillary qubit system. The operation then represents an inversion (NOT gate) on the main system conditioned by the value of f(x) from the ancillary system:

\begin{cases} Uf|x\rang|y\rang=|x\rang|\negy\rang&forx=\omega,thatis,f(x)=1,\\ Uf|x\rang|y\rang=|x\rang|y\rang&forx\ne\omega,thatis,f(x)=0, \end{cases}

or briefly,

Uf|x\rang|y\rang=|x\rang|yf(x)\rang.

These oracles are typically realized using uncomputation.

If we are given Uf as our oracle, then we can also implement Uω, since Uω is Uf when the ancillary qubit is in the state

|-\rang=

1{\sqrt2}(|0\rang
-

|1\rang)=H|1\rang

:

\begin{align} Uf(|x\rang|-\rang) &=

1{\sqrt2}
\left(

Uf|x\rang|0\rang-Uf|x\rang|1\rang\right)\\ &=

1{\sqrt2}
\left(|x\rang

|f(x)\rang-|x\rang|1f(x)\rang\right)\\ &=\begin{cases}

1{\sqrt2}
\left(-|x\rang

|0\rang+|x\rang|1\rang\right)&iff(x)=1,\\

1{\sqrt2}
\left(

|x\rang|0\rang-|x\rang|1\rang\right)&iff(x)=0 \end{cases}\\ &=(U\omega|x\rang)|-\rang \end{align}

So, Grover's algorithm can be run regardless of which oracle is given.[3] If Uf is given, then we must maintain an additional qubit in the state

|-\rang

and apply Uf in place of Uω.

Algorithm

The steps of Grover's algorithm are given as follows:

  1. Initialize the system to the uniform superposition over all states

|s\rangle=

1
\sqrt{N
} \sum_^ |x\rangle.
  1. Perform the following "Grover iteration"

r(N)

times:
    1. Apply the operator

U\omega

    1. Apply the Grover diffusion operator

Us=2\left|s\right\rangle\left\langles\right|-I

  1. Measure the resulting quantum state in the computational basis.

For the correctly chosen value of

r

, the output will be

|\omega\rang

with probability approaching 1 for N ≫ 1. Analysis shows that this eventual value for

r(N)

satisfies

r(N)\leq\lceil

\pi
4

\sqrt{N}\rceil

.

Implementing the steps for this algorithm can be done using a number of gates linear in the number of qubits.[3] Thus, the gate complexity of this algorithm is

O(log(N)r(N))

, or

O(log(N))

per iteration.

Geometric proof of correctness

There is a geometric interpretation of Grover's algorithm, following from the observation that the quantum state of Grover's algorithm stays in a two-dimensional subspace after each step. Consider the plane spanned by

|s\rang

and

|\omega\rang

; equivalently, the plane spanned by

|\omega\rang

and the perpendicular ket

style|s'\rang=

1
\sqrt{N-1
}\sum_ |x\rang.

Grover's algorithm begins with the initial ket

|s\rang

, which lies in the subspace. The operator

U\omega

is a reflection at the hyperplane orthogonal to

|\omega\rang

for vectors in the plane spanned by

|s'\rang

and

|\omega\rang

, i.e. it acts as a reflection across

|s'\rang

. This can be seen by writing

U\omega

in the form of a Householder reflection:

U\omega=I-2|\omega\rangle\langle\omega|.

The operator

Us=2|s\rangle\langles|-I

is a reflection through

|s\rang

. Both operators

Us

and

U\omega

take states in the plane spanned by

|s'\rang

and

|\omega\rang

to states in the plane. Therefore, Grover's algorithm stays in this plane for the entire algorithm.

It is straightforward to check that the operator

UsU\omega

of each Grover iteration step rotates the state vector by an angle of

\theta=2\arcsin\tfrac{1}{\sqrt{N}}

.So, with enough iterations, one can rotate from the initial state

|s\rang

to the desired output state

|\omega\rang

. The initial ket is close to the state orthogonal to

|\omega\rang

:

\langs'|s\rang=\sqrt{

N-1
N
}.

In geometric terms, the angle

\theta/2

between

|s\rang

and

|s'\rang

is given by

\sin

\theta
2

=

1
\sqrt{N
}.

We need to stop when the state vector passes close to

|\omega\rang

; after this, subsequent iterations rotate the state vector away from

|\omega\rang

, reducing the probability of obtaining the correct answer. The exact probability of measuring the correct answer is

\sin2\left((r+

1
2

)\theta\right),

where r is the (integer) number of Grover iterations. The earliest time that we get a near-optimal measurement is therefore

r\pi\sqrt{N}/4

.

Algebraic proof of correctness

To complete the algebraic analysis, we need to find out what happens when we repeatedly apply

UsU\omega

. A natural way to do this is by eigenvalue analysis of a matrix. Notice that during the entire computation, the state of the algorithm is a linear combination of

s

and

\omega

. We can write the action of

Us

and

U\omega

in the space spanned by

\{|s\rang,|\omega\rang\}

as:

Us:a|\omega\rang+b|s\rang\mapsto[|\omega\rang|s\rang]\begin{bmatrix} -1&0\\ 2/\sqrt{N}&1\end{bmatrix}\begin{bmatrix}a\\b\end{bmatrix}.

U\omega:a|\omega\rang+b|s\rang\mapsto[|\omega\rang|s\rang]\begin{bmatrix} -1&-2/\sqrt{N}\\ 0&1\end{bmatrix}\begin{bmatrix}a\\b\end{bmatrix}.

So in the basis

\{|\omega\rang,|s\rang\}

(which is neither orthogonal nor a basis of the whole space) the action

UsU\omega

of applying

U\omega

followed by

Us

is given by the matrix

UsU\omega=\begin{bmatrix}-1&0\ 2/\sqrt{N}&1\end{bmatrix} \begin{bmatrix} -1&-2/\sqrt{N}\\ 0&1\end{bmatrix} =\begin{bmatrix} 1&2/\sqrt{N}\\ -2/\sqrt{N}&1-4/N\end{bmatrix}.

This matrix happens to have a very convenient Jordan form. If we define

t=\arcsin(1/\sqrt{N})

, it is

UsU\omega=M\begin{bmatrix}e2it&0\ 0&e-2it\end{bmatrix}M-1

where

M=\begin{bmatrix}-i&i\eit&e-it\end{bmatrix}.

It follows that r-th power of the matrix (corresponding to r iterations) is

(UsU

r
\omega)

=M\begin{bmatrix}e2rit&0\ 0&e-2rit\end{bmatrix}M-1.

Using this form, we can use trigonometric identities to compute the probability of observing ω after r iterations mentioned in the previous section,

\left|\begin{bmatrix}\lang\omega|\omega\rang&\lang\omega|s\rang\end{bmatrix}(UsU

r
\omega)

\begin{bmatrix}0\ 1\end{bmatrix}\right|2=\sin2\left((2r+1)t\right).

Alternatively, one might reasonably imagine that a near-optimal time to distinguish would be when the angles 2rt and −2rt are as far apart as possible, which corresponds to

2rt\pi/2

, or

r=\pi/4t=\pi/4\arcsin(1/\sqrt{N})\pi\sqrt{N}/4

. Then the system is in state

[|\omega\rang|s\rang](UsU

r
\omega)

\begin{bmatrix}0\\1\end{bmatrix}[|\omega\rang|s\rang]M\begin{bmatrix}i&0\ 0&-i\end{bmatrix}M-1\begin{bmatrix}0\\1\end{bmatrix}=|\omega\rang

1
\cos(t)

-|s\rang

\sin(t)
\cos(t)

.

A short calculation now shows that the observation yields the correct answer ω with error

O\left(

1
N

\right)

.

Extensions and variants

Multiple matching entries

If, instead of 1 matching entry, there are k matching entries, the same algorithm works, but the number of iterations must be \frac instead of \frac.

There are several ways to handle the case if k is unknown.[15] A simple solution performs optimally up to a constant factor: run Grover's algorithm repeatedly for increasingly small values of k, e.g., taking k = N, N/2, N/4, ..., and so on, taking

k=N/2t

for iteration t until a matching entry is found.

With sufficiently high probability, a marked entry will be found by iteration

t=log2(N/k)+c

for some constant c. Thus, the total number of iterations taken is at most
\pi
4

(1+\sqrt{2}+\sqrt{4}++\sqrt{

N
k2c
}\Big) = O\big(\sqrt\big).

Another approach if k is unknown is to derive it via the quantum counting algorithm prior.

If

k=N/2

(or the traditional one marked state Grover's Algorithm if run with

N=2

), the algorithm will provide no amplification. If

k>N/2

, increasing k will begin to increase the number of iterations necessary to obtain a solution.[16] On the other hand, if

k\geqN/2

, a classical running of the checking oracle on a single random choice of input will more likely than not give a correct solution.

A version of this algorithm is used in order to solve the collision problem.

Quantum partial search

A modification of Grover's algorithm called quantum partial search was described by Grover and Radhakrishnan in 2004.[17] In partial search, one is not interested in finding the exact address of the target item, only the first few digits of the address. Equivalently, we can think of "chunking" the search space into blocks, and then asking "in which block is the target item?". In many applications, such a search yields enough information if the target address contains the information wanted. For instance, to use the example given by L. K. Grover, if one has a list of students organized by class rank, we may only be interested in whether a student is in the lower 25%, 25–50%, 50–75% or 75–100% percentile.

To describe partial search, we consider a database separated into

K

blocks, each of size

b=N/K

. The partial search problem is easier. Consider the approach we would take classically – we pick one block at random, and then perform a normal search through the rest of the blocks (in set theory language, the complement). If we don't find the target, then we know it's in the block we didn't search. The average number of iterations drops from

N/2

to

(N-b)/2

.

Grover's algorithm requires \frac\sqrt iterations. Partial search will be faster by a numerical factor that depends on the number of blocks

K

. Partial search uses

n1

global iterations and

n2

local iterations. The global Grover operator is designated

G1

and the local Grover operator is designated

G2

.

The global Grover operator acts on the blocks. Essentially, it is given as follows:

  1. Perform

j1

standard Grover iterations on the entire database.
  1. Perform

j2

local Grover iterations. A local Grover iteration is a direct sum of Grover iterations over each block.
  1. Perform one standard Grover iteration.

The optimal values of

j1

and

j2

are discussed in the paper by Grover and Radhakrishnan. One might also wonder what happens if one applies successive partial searches at different levels of "resolution". This idea was studied in detail by Vladimir Korepin and Xu, who called it binary quantum search. They proved that it is not in fact any faster than performing a single partial search.

Optimality

Grover's algorithm is optimal up to sub-constant factors. That is, any algorithm that accesses the database only by using the operator Uω must apply Uω at least a

1-o(1)

fraction as many times as Grover's algorithm.[18] The extension of Grover's algorithm to k matching entries, (N/k)1/2/4, is also optimal. This result is important in understanding the limits of quantum computation.

If the Grover's search problem was solvable with N applications of Uω, that would imply that NP is contained in BQP, by transforming problems in NP into Grover-type search problems. The optimality of Grover's algorithm suggests that quantum computers cannot solve NP-Complete problems in polynomial time, and thus NP is not contained in BQP.

It has been shown that a class of non-local hidden variable quantum computers could implement a search of an

N

-item database in at most

O(\sqrt[3]{N})

steps. This is faster than the

O(\sqrt{N})

steps taken by Grover's algorithm.[19]

See also

Notes

  1. Book: Grover, Lov K.. Proceedings of the twenty-eighth annual ACM symposium on Theory of computing - STOC '96 . A fast quantum mechanical algorithm for database search . 1996-07-01. https://doi.org/10.1145/237814.237866. Philadelphia, Pennsylvania, USA. Association for Computing Machinery. 212–219. 10.1145/237814.237866. quant-ph/9605043. 1996quant.ph..5043G. 978-0-89791-785-8. 207198067.
  2. The strengths and weaknesses of quantum computation. Bennett C.H. . Bernstein E. . Brassard G. . Vazirani U. . 13403194 . SIAM Journal on Computing. 1997. 26 . 5. 1510 - 1523. 10.1137/s0097539796300933. quant-ph/9701001.
  3. Book: Nielsen, Michael A.. Quantum computation and quantum information. 2010. Cambridge University Press. Isaac L. Chuang. 978-1-107-00217-3. Cambridge. 665137861. 276–305.
  4. Bernstein . Daniel J. . Daniel J. Bernstein . Sendrier . Nicolas . Grover vs. McEliece . https://cr.yp.to/codes/grovercode-20100303.pdf . 10.1007/978-3-642-12929-2_6 . 73–80 . Springer . Lecture Notes in Computer Science . Post-Quantum Cryptography, Third International Workshop, PQCrypto 2010, Darmstadt, Germany, May 25-28, 2010. Proceedings . 6061 . 2010.
  5. Grover . Lov K. . Vitter . Jeffrey Scott . quant-ph/9711043 . A framework for fast quantum mechanical algorithms . 10.1145/276698.276712 . 53–62 . Association for Computing Machinery . Proceedings of the Thirtieth Annual ACM Symposium on the Theory of Computing, Dallas, Texas, USA, May 23–26, 1998 . 1998.
  6. Ambainis. A.. 2004-06-01. Quantum search algorithms. ACM SIGACT News. 35. 2. 22–35. 10.1145/992287.992296. 11326499. 0163-5700. quant-ph/0504012.
  7. Web site: Jordan. Stephen. Quantum Algorithm Zoo. 2021-04-21. quantumalgorithmzoo.org. en.
  8. Cerf. Nicolas J.. Grover. Lov K.. Williams. Colin P.. 2000-05-01. Nested Quantum Search and NP-Hard Problems. Applicable Algebra in Engineering, Communication and Computing. en. 10. 4. 311–338. 10.1007/s002000050134. 311132. 1432-0622.
  9. Ambainis. Andris. 2007-01-01. Quantum Walk Algorithm for Element Distinctness. SIAM Journal on Computing. 37. 1. 210–239. 10.1137/S0097539705447311. 6581885. 0097-5397. quant-ph/0311001.
  10. Brassard . Gilles . Høyer . Peter . Tapp . Alain . Lucchesi . Claudio L. . Moura . Arnaldo V. . quant-ph/9705002 . Quantum Cryptanalysis of Hash and Claw-Free Functions . 10.1007/BFb0054319 . 163–169 . Springer . Lecture Notes in Computer Science . LATIN '98: Theoretical Informatics, Third Latin American Symposium, Campinas, Brazil, April, 20-24, 1998, Proceedings . 1380 . 1998.
  11. Book: Post-quantum cryptography. 2009. Springer. Daniel J. Bernstein, Johannes Buchmann, Erik, Dipl.-Math Dahmén. 978-3-540-88702-7. Berlin. 318545517.
  12. Bernstein. Daniel J.. 2021-04-21. Cost analysis of hash collisions: Will quantum computers make SHARCS obsolete?. Conference Proceedings for Special-purpose Hardware for Attacking Cryptographic Systems (SHARCS '09). 09. 105–117.
  13. Sinitsyn N. A.. Yan B.. Topologically protected Grover's oracle for the partition problem. Physical Review A. 2023. 108. 2. 022412. 10.1103/PhysRevA.108.022412. 2304.10488. 258236417.
  14. Babbush. Ryan. McClean. Jarrod R.. Newman. Michael. Gidney. Craig. Boixo. Sergio. Neven. Hartmut. 2021-03-29. Focus beyond Quadratic Speedups for Error-Corrected Quantum Advantage. PRX Quantum. 2. 1. 010103. 10.1103/PRXQuantum.2.010103 . 2011.04149 . free.
  15. Web site: Aaronson. Scott. April 19, 2021. Introduction to Quantum Information Science Lecture Notes.
  16. Nielsen-Chuang
  17. quant-ph/0407122v4. Is partial quantum search of a database any easier?. L.K. Grover . J. Radhakrishnan . 2005-02-07.
  18. Zalka. Christof. 1999-10-01. Grover's quantum searching algorithm is optimal. Physical Review A. 60. 4. 2746–2751. 10.1103/PhysRevA.60.2746. quant-ph/9711070. 1999PhRvA..60.2746Z. 1542077.
  19. Web site: Quantum Computing and Hidden Variables. Aaronson. Scott.

References

External links