# References

SEARCHING IN GROVER’S ALGORITHM   
Richard Jozsa

School of Mathematics and Statistics

University of Plymouth

Plymouth, Devon PL4 8AA, England.

Email: rjozsa@plymouth.ac.uk

ABSTRACT

Grover’s algorithm is usually described in terms of the iteration of a compound operator of the form $`Q=HI_0HI_{x_0}`$. Although it is quite straightforward to verify the algebra of the iteration, this gives little insight into why the algorithm works. What is the significance of the compound structure of $`Q`$? Why is there a minus sign? Later it was discovered that $`H`$ could be replaced by essentially any unitary $`U`$. What is the freedom involved here? We give a description of Grover’s algorithm which provides some clarification of these questions.

INTRODUCTION

Grover’s quantum searching algorithm is usually described  in terms of the iteration of a compound operator $`Q`$ of the form

$$Q=HI_0HI_{x_0}$$
(1)   
on a starting state $`|\psi _0=H|0`$. Here $`H`$ is the Walsh-Hadamard transform and $`I_0,I_{x_0}`$ are suitable inversion operators (c.f. below).<sup>1</sup><sup>1</sup>1 This $`Q`$ is the one used in . Grover  uses instead $`Q^{GR}=I_0HI_{x_0}H`$ iterated on $`|\psi _0=|0`$ which is clearly an equivalent process. Later it was discovered  that $`H`$ may be replaced by essentially any unitary operation $`U`$ and using

$$Q=UI_0U^1I_{x_0}|\psi _0=U|0$$
(2)   
the searching algorithm still works just as well as before (with at most a constant slowdown in the number of iterations). At first sight this appeared remarkable since $`H`$ is known to be singularly significant for other quantum algorithms . The efficacy of these other algorithms could be understood in terms of the fast Fourier transform construction  but Grover’s algorithm appears to rest on different principles. Although it is quite straightforward to work through the algebra of the algorithm , this provides little insight into why it works! The operator $`HI_0H`$ was originally called a “diffusion” operator  and later interpreted as “inversion in the average”  but neither of these appears to provide much heuristic insight (especially in the context of the more general eq. (2)). What is the significance of the particular compound structure of $`Q`$ for a searching problem? What is the significance of the minus sign in $`Q`$? Why can $`H`$ be replaced by an arbitrary $`U`$ – what is the freedom involved here? The purpose of this note is to give a different description of Grover’s algorithm which provides some clarification of these issues. We will show that the algorithm may be seen to be a consequence of the following elementary theorem of 2-dimensional real Euclidean geometry:   
Theorem 1: Let $`M1`$ and $`M2`$ be two mirror lines in the Euclidean plane $`\text{IR}^2`$ intersecting at a point $`O`$ and let $`\alpha `$ be the angle in the plane from $`M1`$ to $`M2`$. Then the operation of reflection in $`M1`$ followed by reflection in $`M2`$ is just rotation by angle $`2\alpha `$ about the point $`O`$.   
Figure 1. Reflection in $`M1`$ followed by reflection in $`M2`$ is equivalent to rotation about $`O`$ through angle $`2\alpha `$.   

THE SEARCH PROBLEM

The search problem is often phrased in terms of an exponentially large unstructured database with $`N=2^n`$ records, of which one is specially marked. The problem is to locate the special record. Elementary probability theory shows that classically if we examine $`k`$ records then we have probability $`k/N`$ of finding the special one so we need $`O(N)`$ such trials to find it with any constant (independent of $`N`$) level of probability. Grover’s quantum algorithm achieves this result with only $`O(\sqrt{N})`$ steps (or more precisely $`O(\sqrt{N})`$ iterations of $`Q`$ but $`O(\sqrt{N}\mathrm{log}N)`$ steps, the $`\mathrm{log}N`$ term coming from the implementation of $`H`$.) It may be shown  that the square root speedup of Grover’s algorithm is optimal within the context of quantum computation.

The search problem may be more accurately phrased in terms of an oracle problem, which we adopt here. In the description above, there is a potential difficulty concerning the physical realisation of an exponentially large unstructured database. One might expect that it will require exponentially many degrees of freedom of some physical resource, such as space, and consequently it may need exponential (i.e. $`O(N)`$) effort or time just to access a typical (remotely lying) record. We will replace the database by an oracle which computes an $`n`$ bit function $`f:B^nB`$ (where $`B=\{0,1\}`$). It is promised that $`f(x)=0`$ for all $`n`$ bit strings except exactly one string, denoted $`x_0`$ (the “marked” position) for which $`f(x_0)=1`$. Our problem is to determine $`x_0`$. We assume as usual that $`f`$ is given as a unitary transformation $`U_f`$ on $`n+1`$ qubits defined by

$$U_f|x|y=|x|yf(x)$$
(3)   
Here the input register $`|x`$ consists of $`n`$ qubits as $`x`$ ranges over all $`n`$ bit strings and the output register $`|y`$ consists of a single qubit with $`y=0`$ or 1. The symbol $``$ denoted addition modulo 2.   
Figure 2. The action of $`U_f`$ on a general basis state $`|x|y`$ of the input and output registers.   
The assumption that the database was unstructured is formalised here as the standard oracle idealisation that we have no access to the internal workings of $`U_f`$ – it operates as a “black box” on the input and output registers. In this formulation there is no problem with the access to $`f(x)`$ for any of the exponentially many $`x`$ values and indeed we may also readily query the oracle with a superposition of input values.

Instead of using $`U_f`$ we will generally use an equivalent operation denoted $`I_{x_0}`$ on $`n`$ qubits. It is defined by

$$I_{x_0}|x=\{\begin{array}{cc}\hfill |x& \text{if }xx_0\text{ }\hfill \\ \hfill |x_0& \text{if }x=x_0\hfill \end{array}$$
(4)   
i.e. $`I_{x_0}`$ simply inverts the amplitude of the $`|x_0`$ component. If $`x_0`$ is the $`n`$ bit string $`00\mathrm{}0`$ then $`I_{x_0}`$ will be written simply as $`I_0`$.

A black box which performs $`I_{x_0}`$ may be simply constructed from $`U_f`$ by just setting the output register to $`\frac{1}{\sqrt{2}}(|0|1)`$. Then the action of $`U_f`$ leaves the output register in this state and effects $`I_{x_0}`$ on the input register<sup>2</sup><sup>2</sup>2Note that, conversely, $`U_f`$ may be constructed from the a black box for $`I_{x_0}`$ as follows. Let $`J_{x_0}`$ denote the operation “$`I_{x_0}`$ controlled by the output qubit”. Apply $`H`$ to the output register, then $`J_{x_0}`$ to the input and output registers, then $`H`$ again to the output register. The total effect is just $`U_f`$ on the $`n+1`$ qubits of both registers, as the reader may verify. To construct $`J_{x_0}`$ from $`I_{x_0}`$ we also need an eigenstate of $`I_{x_0}`$. The construction is described in  or .:   
Figure 3. Construction of $`I_{x_0}`$ from $`U_f`$. Here $`|\psi `$ is any $`n`$-qubit state.   

Our searching problem becomes the following: we are given a black box which computes $`I_{x_0}`$ for some $`n`$ bit string $`x_0`$ and we want to determine the value of $`x_0`$.

REFLECTIONS ON REFLECTIONS

We first digress briefly to record some elementary properties of reflections which will provide the basis for our interpretation of Grover’s algorithm.   
In two real dimensions:   
In real 2 dimensional Euclidean space, let $`M`$ be any straight line through the origin specified by a unit vector $`v`$ perpendicular to $`M`$. Let $`I_v`$ denote the operation of reflection in $`M`$. Note that if $`u`$ is any vector we may write it uniquely as a sum of components parallel and perpendicular to $`v`$. If $`v^{}`$ is a unit vector lying along $`M`$ then we have

$$u=av+bv^{}$$

and $`I_v`$ simply replaces $`a`$ by $`a`$.   
In $`N`$ complex dimensions:   
Note that $`I_v`$ is exactly like $`I_{x_0}`$ in eq. (4) above except that there, we were in a complex space of higher dimension. We may interpret $`I_{x_0}`$ as a reflection in the hyperplane orthogonal to $`|x_0`$. In terms of formulas, to reflect the $`x_0`$ amplitude we have

$$I_{x_0}=I2|x_0x_0|$$
(5)   
where $`I`$ is the identity operator. More generally if $`|\psi `$ is any state we define

$$I_{|\psi }=I2|\psi \psi |$$
(6)   
Then $`I_{|\psi }`$ is the operation of reflection in the hyperplane<sup>3</sup><sup>3</sup>3More generally, for any subspace $`D`$ we may define $`I_D`$ by $`I_D=I2_d|dd|`$ where $`\{|d\}`$ is any orthonormal basis of $`D`$. Then $`I_D`$ is reflection in the orthogonal complement $`D^{}`$ of the subspace $`D`$. orthogonal to $`|\psi `$. For any state $`|\chi `$ we may uniquely express it as a sum of components parallel and orthogonal to $`|\psi `$ and $`I_{|\psi }`$ simply inverts the parallel component.

We have the following simple properties of $`I_{|\psi }`$:   
Lemma 1: If $`|\chi `$ is any state then $`I_{|\psi }`$ preserves the 2-dimensional subspace $`𝒮`$ spanned by $`|\chi `$ and $`|\psi `$.   
Proof: Geometrically, $`𝒮`$ and the mirror hyperplane are orthogonal to each other (in the sense that the orthogonal complement of either subspace is contained in the other subspace) so the reflection preserves $`𝒮`$. Alternatively in terms of algebra, eq. (6) shows that $`I_{|\psi }`$ takes $`|\psi `$ to $`|\psi `$ and for any $`|\chi `$, it adds a multiple of $`|\psi `$ to $`|\chi `$. Hence any linear combination is mapped to a linear combination of the same two states $`\mathrm{}`$.   
Lemma 2: For any unitary operator $`U`$

$$UI_{|\psi }U^1=I_{U|\psi }$$

Proof: Geometrically we are just changing description (reference basis) by $`U^1`$ but the result is also immediate from eq. (6):

$$UI_{|\psi }U^1=I2U|\psi \psi \left|U^1=I2\right|U\psi U\psi |=I_{U|\psi }\mathrm{}.$$

Looking back at eq. (2) we see that

$$Q=I_{U|0}I_{|x_0}$$
(7)   
Back to two real dimensions:   
By lemma 1, both $`I_{x_0}`$ and $`I_{U|0}`$ preserve the two dimensional subspace $`𝒱`$ spanned by $`|x_0`$ and $`U|0`$ . Hence by eq. (7), $`Q`$ preserves $`𝒱`$ too. Now we may introduce a basis $`\{|e_1,|e_2\}`$ into $`𝒱`$ such that $`U|0`$ and $`|x_0`$ up to an overall phase, have real coordinates. Indeed choose $`|e_1=U|0`$ so $`U|0`$ has coordinates $`(1,0)`$. Then $`e^{i\xi }|x_0=a|e_1+b|e_2`$ where $`|e_2`$, orthonormal to $`|e_1`$, still has an overall phase freedom. Thus choose $`\xi `$ to make $`a`$ real and the phase of $`|e_2`$ to make $`b`$ real. Then in this basis, since $`U|0`$ and $`|x_0`$ have real coordinates, the operators $`I_{x_0}`$ and $`I_{U|0}`$ when acting on $`𝒱`$, are also described by real 2 by 2 matrices – in fact they are just the real 2 dimensional reflections in the lines perpendicular to $`|x_0`$ and $`U|0`$ in $`𝒱`$. Finally we have:   
Lemma 3: For any 2 dimensional real $`v`$ we have

$$I_v=I_v^{}$$

where $`v^{}`$ is a unit vector perpendicular to $`v`$.   
Proof: For any vector $`u`$ we write $`u=av+bv^{}`$. Then $`I_v`$ just reverses the sign of $`a`$ and $`I_v`$ reverses the sign of $`b`$. Thus the action of $`I_v`$ is the same as that of $`I_v^{}`$ $`\mathrm{}`$.

Later, this lemma will explain the significance of the minus sign in eq. (2). For the present, note that from eq. (7) we can write

$$Q=I_{|w}I_{|x_0}$$

where $`|w`$ is orthogonal to $`U|0`$ and lies in the plane of $`U|0`$ and $`|x_0`$. Since we are working with real coordinates, theorem 1 shows that $`Q`$, acting in $`𝒱`$, is just the operation of rotation through angle $`2\alpha `$ where $`\alpha `$ is the angle between $`|w`$ and $`|x_0`$ i.e. $`\mathrm{cos}\alpha =x_0|w`$. Since $`U|0`$ is perpendicular to $`|w`$ we can write $`\mathrm{sin}\alpha =x_0|U|0`$.

GROVER’S ALGORITHM

We now give an interpretation of the workings of the quantum searching algorithm in view of the preceeding simple facts about reflections. Given the black box $`I_{x_0}`$ how can we identify $`x_0`$? Surely we must apply $`I_{x_0}`$ to some state (we can do nothing else with a black box!) but there seems no reason a priori to choose any one state rather than any other. So let us just choose a state $`|w`$ at random. $`|w`$ may be written as $`U|0`$ where $`U`$ is chosen at random.

Now by lemma 1, $`I_{x_0}`$ preserves the subspace spanned by $`|w`$ and $`|x_0`$ and by theorem 1, $`I_{|w}I_{x_0}`$ provides a way of moving around in this subspace – it is just rotation by twice the angle between $`|x_0`$ and $`|w`$. (Note that $`I_{|w}`$ may be constructed via lemma 2 as $`UI_0U^1`$.) The idea now is to try to use this motion to move from the known starting state $`|w`$ towards the unknown $`|x_0`$. This process has been called “amplitude amplification”  as we are effectively trying to enhance the amplitude of the $`|x_0`$ component of the state. Once we are near to $`|x_0`$ then a measurement of the state in the standard basis $`\{|x\}`$ will reveal the value of $`x_0`$ with high probability.

However there is an apparent problem: we do not know $`x_0`$ so we know neither the angle $`\beta `$, between $`|x_0`$ and $`|w`$, nor the angle $`2\beta `$ of rotation of $`I_{|w}I_{x_0}`$. Hence we do not know how many times to apply the rotation to move $`|w`$ near to $`|x_0`$. Remarkably we can solve this problem by using the extra information that $`|x_0`$ is known to be a member of a particular basis $`\{|x\}`$ of $`N`$ orthonormal states! If we choose

$$|w_0=\frac{1}{\sqrt{N}}\underset{x}{}|x$$
(8)   
to be a uniform superposition of all the $`|x`$’s then whatever the value of $`x_0`$ is, we have that $`x_0|w_0=\frac{1}{\sqrt{N}}`$ and hence we will know that the angle $`\beta `$ is given by $`\mathrm{cos}\beta =\frac{1}{\sqrt{N}}`$ in every possible case! Note that for large $`N`$ (the usual case of interest) $`|x_0`$ and $`|w_0`$ are nearly orthogonal so $`2\beta `$ is near to $`\pi `$. This will typically be the case for any $`|w`$ chosen at random in a large Hilbert space – it will tend with high probability to be nearly orthogonal to any previously fixed state such as $`|x_0`$.

Now, $`I_{|w}I_{x_0}`$ rotating through nearly $`\pi `$, acts rather wildly on the space, moving vectors through a great distance and we would prefer to have a gentler incremental motion of $`|w_0`$ towards $`|x_0`$. One way of doing this is to use instead, the operation $`(I_{|w_0}I_{x_0})^2`$ rotating through $`4\beta `$ which is near to $`2\pi `$ i.e. 0 mod $`2\pi `$. Since $`\mathrm{cos}\beta =\frac{1}{\sqrt{N}}`$ we have that $`4\beta `$ mod $`2\pi `$ is $`O(\frac{1}{\sqrt{N}})`$. (To see this, write $`\beta =\frac{\pi }{2}\alpha `$ so $`\mathrm{sin}\alpha =\mathrm{cos}\beta =\frac{1}{\sqrt{N}}`$. Then $`4\beta =2\pi 4\alpha `$ and $`\alpha \frac{1}{\sqrt{N}}`$ for large $`N`$). Now the angle between $`|w_0`$ and $`|x_0`$ is nearly $`\pi /2`$ so we will need $`O(\sqrt{N})`$ iterations of this rotation to move $`|w_0`$ near to $`|x_0`$. A second way of dealing with the large $`\beta `$ problem – the way actually used in Grover’s algorithm – is to simply put a minus sign in front of $`I_{|w_0}I_{x_0}`$! This explains the role of the minus sign in eq. (2). Indeed by lemma 3, $`I_{|w}I_{x_0}=I_{|w_0^{}}I_{x_0}`$ where $`|w_0^{}`$ is orthogonal to $`|w_0`$ in the subspace spanned by $`|w_0`$ and $`|x_0`$ and now the angle $`\alpha `$ between $`|w_0^{}`$ and $`|x_0`$ is given by $`\mathrm{cos}\alpha =x_0|w^{}`$ i.e. $`\mathrm{sin}\alpha =x_0|w`$ so $`\alpha \frac{1}{\sqrt{N}}`$. Again we will need $`O(\sqrt{N})`$ iterations of the rotation $`I_{w_0}I_{x_0}`$ through $`2\alpha `$ to span the angle between $`|w_0`$ and $`|x_0`$.

In conclusion, we choose the starting state $`|w_0`$ of eq. (8) and apply $`O(\sqrt{N})`$ times, the operator

$$Q=I_{|w_0^{}}I_{x_o}=I_{|w_0}I_{x_0}=UI_0U^1I_{x_0}$$

where $`U`$ is any unitary operation with $`U|0=|w_0`$ (for example $`U=H`$). The significance of the minus sign (in the context of reflection operations) is to convert a nearly orthogonal pair of directions to a nearly parallel pair (c.f. lemma 3) . The composite structure of $`Q`$ is just to build a rotation as a product of two reflections (c.f. theorem 1) and the random choice of $`U`$ just picks a random starting state in the two dimensional subspace, which is then moved towards $`|x_0`$. The exact number of iterations of $`Q`$ required depends on knowledge of the angle between $`|x_0`$ and $`U|0`$. If $`U|0=|w_0=\frac{1}{\sqrt{N}}_x|x`$ then this is explicitly known, but if $`U`$ is chosen more generally at random then we will not know this angle. However $`Q`$ will still generally be a small rotation through some angle of order $`O(\frac{1}{\sqrt{N}})`$ but we will not know when to stop the iterations. Nevertheless the process will still move $`U|0`$ near to $`|x_0`$ in $`O(\sqrt{N})`$ steps. It will fail only in the unlikely situation that the randomly chosen $`U|0`$ happens to be exactly orthogonal to the unknown $`|x_0`$ (i.e. $`U`$ has zero matrix element $`U_{0x_0}`$ as noted in ). $`Q`$ is then a rotation through an angle of zero.

Having identified $`W`$ as a rotation through $`2\alpha `$ in the plane $`𝒱`$ of $`|x_0`$ and $`|w_0`$, where $`\alpha `$ is defined by

$$\mathrm{sin}\alpha =\frac{1}{\sqrt{N}}$$
(9)   
(for the case that $`U|0=|w_0`$) we may readily calculate the motion of $`|\psi _0=|w_0=\frac{1}{\sqrt{N}}_x|x`$ towards $`|x_0`$ by iterated application of $`W`$. In $`𝒱`$ introduce the basis $`\{|x_0,|x_0^{}\}`$ where $`|x_0^{}=\frac{1}{\sqrt{N1}}_{xx_0}|x`$. Then from eq. (9) we get

$$|\psi _0=\mathrm{sin}\alpha |x_0+\mathrm{cos}\alpha |x_0^{}$$

If we write

$$|\psi _{n+1}=Q|\psi _n\text{and}|\psi _n=\mathrm{sin}\alpha _n|x_0+\mathrm{cos}\alpha _n|x_0^{}$$

then we immediately get from the interpretation of $`Q`$ as a rotation through $`2\alpha `$

$$\alpha _{n+1}=\alpha _n+2\alpha \text{i.e. }\alpha _n=(2n+1)\alpha $$

giving the solution of the iteration derived in . For a more general choice $`|\psi _0=|w`$ of starting state, the value of $`\alpha `$, given by $`\mathrm{sin}^1|x_0|w|`$, will generally be unknown but the application of $`W`$ still increments the angle successively by $`2\alpha `$ as above. The number of iterations is chosen to make $`\alpha _n`$ as close as possible to $`\pi /2`$.

Acknowledgement

After this note was completed it came to my attention that various other workers were aware of the significance of double reflections for Grover’s algorithm. However it appears not to be widely known and I present this note for its pedagogical value.