5.3 Searching with Grover
After returning safely back to Earth, Hila and Iman have become good friends with Alice and Bob. The four of them decide to spend New Year’s Eve together. This day also coincides with the drawing of the annual quantum lottery! They know that only one of the four can win the grand prize, but who will it be? If we label our four protagonists by bitstrings, say,
then we can model the lottery by a function which evaluates to 1 for the bitstring corresponding to the winner. For example, if then Hila is the winner of this year’s lottery.
How can our friends determine the winner? Using a classical algorithm they have to evaluate the function up to three times to determine the winner. Indeed, suppose that they learn that and – then they still do not know whether Alice or Iman is the winner! For archaic reasons that have long been forgotten, the rules of the lottery only allow evaluating the function once. But naturally, the lottery is happy to apply the sign oracle to any two-qubit states of our protagonists’ liking – after all, it is a quantum lottery…
Alice and her friends get together and start pondering. After a while, Bob grows impatient and suggests: “Let us just follow the first few steps of Deutsch-Jozsa and Bernstein-Vazirani – surely the same trick will work once again…” The others do not really know of a better alternative, so they go ahead and prepare the state
Next, they hand the state to the quantum lottery, which applies the sign oracle and returns the state. Let and denote the two bits that label the winner, i.e., and all other function values are zero. Then the two-qubit state returned by the lottery is the following:
where the in the first line replaces one of the plus signs by a minus sign. After applying a Hadamard transform, they arrive at the following state:
Now our friends are confused and not quite sure what to do. Hila has an idea: “I don’t really like the minus sign in front of . Why don’t we apply a quantum operation that looks as follows?”
Iman joins in: “I think I know how to build this using a controlled-Z operation and a handful of NOTs…” In no time, our friends arrive at the following state:
After only a brief moment, Alice realizes: “This two-qubit state can be written as a tensor product!”
Bob is elated: “Aha! We only need to apply another Hadamard transform and measure both qubits…” Can you also figure out who the winner of this year’s quantum lottery will be?
Homework 5.5 (Quantum lottery).
-
1.
Write the quantum operation in Eq. 5.16 using a controlled-Z operation and a few NOT operations.
Hint: Recall that the controlled-Z operation acts on basis states as follows: If then it does nothing. If then it acts as a on the second qubit. You learned last week how to build it in Quirky.
-
2.
Build the quantum algorithm that Alice, Bob, Hila, and Iman came up with in Quirky, and determine the winner of this year’s quantum Lottery.
Hack.
-
1.
We can write the quantum operation in Eq. 5.16 as
This works, because works as follows (from the hint and what does)
This is almost what we want, if only we could switch the roles of and in all the input and the output bits. But this is precisely what does! So we apply on all bits before and after the .
- 2.
The quantum algorithm that our friends just discovered is a special case of Grover’s algorithm. Grovers algorithm solves the following problem: Given an oracle for a function , it finds such that . We can think of this problem as finding a lottery winner among participants or, less prosaically, finding an item that satisfies some property of interest in an unstructured database (by which we mean that the database entries are not sorted or similarly). By the same argument that we gave before, any classical algorithm will in the worst case need to look at all but one of the many entries before it is done (also in the average case one still needs to look at about half the entries). In contrast, Grover’s algorithm only needs to use the oracle only a number of times that is proportional to , which grows much more slowly with ! Grover’s algorithm is a very versatile tool which gives a square-root speedup for many computational problems.