I am trying to understand Grover's algorithm without much of a background in quantum. I believe I understood the main parts to be:
- The quantum state is initialized to represent all $n$ possible solutions with equal amplitude/probability;
- Using the oracle, the quantum state flips the sign of the amplitude corresponding to the correct solution;
- Compute the mean amplitude, and reflect all amplitudes over the mean;
- Repeat steps 2 and 3 $O(\sqrt{n})$ times;
- Observe the quantum state (at which point it has a high probability to output the correct solution).
First of all, is my (general and non-quantum background) understanding mostly correct?
And secondly, I tried applying this on a simple example, with $n=4$ possible solutions:
- Initialize a quantum state with 4 amplitudes of $\frac{1}{2}$ or probabilities of $\frac{1}{4}$;
- One of these amplitudes is flipped to $-\frac{1}{2}$;
- The mean amplitude is $\frac{1}{4}$, and the flipped amplitudes result in 3 amplitudes of 0 and 1 amplitude of 1;
- Steps 2 and 3 are repeated some amount of times, but a circular pattern emerges every three iterations: from amplitudes $(\frac{1}{2}, \frac{1}{2}, \frac{1}{2}, \frac{1}{2})$ to $(0, 0, 0, 1)$ as observed above,to $(-\frac{1}{2}, -\frac{1}{2}, -\frac{1}{2}, \frac{1}{2})$, to $(-\frac{1}{2}, -\frac{1}{2}, -\frac{1}{2}, -\frac{1}{2})$, to $(0, 0, 0, -1)$, to $(\frac{1}{2}, \frac{1}{2}, \frac{1}{2}, -\frac{1}{2})$, and finally back to $(\frac{1}{2}, \frac{1}{2}, \frac{1}{2}, \frac{1}{2})$;
- Observing the quantum state is highly likely to output the correct solution, but only if it is done in the above specific $(0, 0, 0, \pm 1)$ states; in the other states it is equally likely to output an incorrect solution.
What am I misunderstanding here? I thought at first that the more iterations meant the closer the probability of a correct solution approaches to 1 (PTAS style if you will), but this is clearly not the case in the above example. Then I thought that there must be a predetermined number of iterations for which the probability of a correct solution is close to 1, but all I could find (that I could understand) was on Wikipedia (paraphrased from the Algorithm section):
Analysis shows that the eventual number of iterations $r(n)$ satisfies $r(n) = O(\sqrt{n})$.
Am I to understand that Grover's algorithm is not a real algorithm in the sense that you could give it an input and find an actual solution, since you don't know the number of iterations you'd need to do? In other words, is Grover's algorithm more of an existential result, i.e. there exists some number of iterations bounded by $O(\sqrt{n})$ for which finding a solution is possible? Or is the fault with me testing it on a (too) small example, for which the result somehow doesn't hold?




