Lesson 17: Amplitude amplification
Boosting any algorithm’s success chance, even when you don’t know the odds
The interactive version checks every answer, gives hints and saves your progress in this browser. This page is the same lesson on one page, with the answers folded away.
1 / 13 · Learn
Before you start
Lesson 16 found a marked item among by turning a state step by step toward it. This lesson keeps the turning and drops the search. Take any quantum algorithm whose result is good with probability : the same kind of step raises that chance close to 1 in about rounds, where rerunning the algorithm takes about tries.
Then: what to do when you don’t know , and what the speed-up does not give you.
By the end of this lesson you can:
- write the iterate for any algorithm , and build it in code;
- explain why turns the state by , where , and compute the success chance after rounds;
- choose the number of rounds, and compare the cost with rerunning;
- succeed without knowing , by choosing the number of rounds at random;
- say what Grover search does not do: it is no faster database lookup, and its square-root gain cannot be beaten.
Check yourself
A warm-up: make a guess before reading on. The lesson comes back to it.
An algorithm gives a good answer with probability , and you can check any answer. Rerunning until it succeeds takes about runs, so if becomes 100 times smaller, rerunning costs 100 times more. This lesson’s method replaces rerunning. If becomes 100 times smaller, how does the cost of that method change?
- AIt grows 100 times too: nothing beats rerunning
- BIt grows about 10 times
- CIt grows by a fixed amount: about 7 more rounds
- DIt doesn’t change: one quantum run checks every answer at once
Show the answer
Answer: B. It grows about 10 times
Each round turns the state by , where , and it has to turn through about . For small , radians, so it takes about rounds: 100 times smaller means 10 times more rounds.
Why not the others
- A. Rerunning grows like , but it is not the only option. Amplitude amplification turns the state by a fixed angle per round, and the number of rounds grows like : 100 times smaller costs only 10 times more.
- C. That would be a logarithmic cost, like halving an interval 7 times. Amplitude amplification gains a square root, not more: 100 times smaller needs about 10 times as many rounds, and no method does better in general.
- D. A run on a superposition still ends in one measurement with one random result. The good results have to be made likely first, and that takes rounds: about of them.
Check yourself
A warm-up: make a guess before reading on. The lesson comes back to it.
A Grover search over items is tuned for one marked item: it makes 6 iterations, which find that item with probability 99.7%. Unknown to you, 4 items are marked. With the same 6 iterations, what is the chance of finding a marked item?
- AOver 99.7%: more marked items are easier to find
- BAbout 99.7%: the number of marked items doesn’t matter
- CAbout 6.3%, the chance of a random guess
- DAbout 2.0%, worse than a random guess
Show the answer
Answer: D. About 2.0%, worse than a random guess
With one marked item , so , and 6 iterations reach . With 4 marked items doubles: , and the same 6 iterations reach about , past at and nearly round to the unmarked side. The chance is , while a random guess gets .
Why not the others
- A. More marked items make each iteration turn the state further: is twice . 6 iterations then carry the state past the marked items, so more turning is not better here.
- B. The angle of each iteration depends on how many items are marked. With 4 of them is about twice as large, so 6 iterations turn the state about twice as far as planned.
- C. The iterations are not wasted: they move the state, just too far. It ends close to the unmarked states, and the chance, 2.0%, is below even a random guess.
2 / 13 · Learn
From search to any algorithm
Grover search starts from , which gives every item the same small amplitude. Many problems allow a better start: some circuit that is already right with probability .
So let be any circuit with no measurements in it, and call some outcomes good. You need a way to recognize them, nothing more. Measuring gives a good outcome with probability , and rerunning until one appears takes runs on average. Amplitude amplification does better with one iterate:
- flips the sign of every good basis state;
- undoes (possible because is unitary);
- flips the sign of alone;
- runs again.
Read the product right to left: acts first. The minus sign in front is a global phase.
First , then rounds of , then a measurement in the 0/1 basis. Inside each round the four pieces act in time order, which is the reverse of their order in the product .
Check yourself
Which piece of needs to know what a good outcome looks like?
- ANone: finds the good outcomes by trying them all
- B and : the algorithm has to aim at the good outcomes
- C
- D
Show the answer
Answer: C.
Only depends on which outcomes are good. depends only on the number of qubits, and is the given algorithm. In search, is the oracle; in general, recognizing a good outcome is often far easier than producing one.
Why not the others
- A. never reads out every outcome. Its only contact with the problem is , which flips the sign of the good states. Without it, would have nothing to steer toward.
- B. is the algorithm you already had. It doesn’t need to know which of its outcomes are good, only to produce them with some probability . Recognizing them is the job of .
- D. only singles out the all-zeros state , the input of . It is the same circuit for every problem on the same number of qubits.
Grover search is the special case , with “good” meaning marked. Then for marked items among , is the oracle, and is the diffusion step, the reflection about the uniform superposition .
For any , the same holds with in place of : .
A map that keeps one direction and flips the sign of every direction at right angles to it is a reflection, like a mirror whose line is that direction. The formula says that half of is a reflection in the line of . Check the claim on itself, one piece at a time, and watch the signs.
Check yourself
Let . Follow through , one piece at a time. What comes out?
- A
- BA state closer to the good outcomes
- C
- D, unchanged
Hints
- Start with : what is it?
- Then flips the sign of , runs, and the leading minus sign acts last.
Show the answer
Answer: D. , unchanged
, then flips it to , gives , and the minus sign in front restores . A state orthogonal to instead ends with a minus sign, so is a mirror whose line is .
Why not the others
- A. alone would do that, but runs again at the end and brings it back: the net effect on is no change at all.
- B. This half of only reflects: it keeps the line of and flips the sign of everything orthogonal to it. The turn toward the good states comes from combining both halves, as the next segments show.
- C. Through the pieces: , gives , gives . You still need the minus sign in front of , which makes it .
3 / 13 · Explore
One round on one qubit
The smallest example has one qubit. , Qiskit’s ry, turns into , and its inverse is . Take :
Call good, so . Then , which flips the sign of , and , which flips the sign of .
Predict, then see
succeeds with . After and one round of , what is the chance of measuring ?
- A: the chance triples
- B1: the result is every time
- C: every piece only flips signs or undoes , so the chance can’t change
- D: each round adds another
Where did the extra probability come from? In a sentence or two: how can steps that only flip signs or undo change a probability?
Show what happens
What happens: B. 1: the result is every time
Write with , since . Step by step: gives , at ; turns that back by to ; flips the first entry, ; turns forward by to . That is , and with the minus sign in front of , exactly . The good amplitude went from to : one round turned the state by .
Why not the others
- A. The program gives 1. For small the good amplitude roughly triples in the first round, so the chance grows about ninefold, not threefold. Here is not small, and the exact rule is a turn from to .
- C. Each sign flip alone leaves the chances alone, but and sit between the flips and mix the amplitudes. A sign flipped before the mixing changes what comes out after it: the program shows going from 25% to 100%.
- D. Adding about per try is how rerunning behaves. acts on amplitudes instead: it turns the state by a fixed angle, and here one turn lands exactly on .
4 / 13 · Learn
Two reflections make a rotation
The example is no accident. Split into its good and bad parts:
where , is the normalized good part and the normalized rest. Both halves of are mirrors in the plane of these two states:
- flips the part: a mirror along ;
- keeps and flips what is orthogonal to it: a mirror along .
Two mirrors whose lines meet at angle make a rotation by . So each round turns the state further toward , and after rounds
The chance of a good outcome is .
Step 1 · mirror in the bad axis
Step 2 · mirror in the start line
The example from above, , so . Step 1 mirrors in the axis, to . Step 2 mirrors that in the line of , to , which is . The net effect is a turn by .
Check yourself
An algorithm already succeeds with . You apply one round of anyway. What is the chance of a good outcome now?
Hints
- Find from .
- . After one round the angle is .
Show the answer
Answer:
, so . One round turns the state to , which is , and . Above one round already makes things worse; there you would just run and check.
Common slips
- : One round lands on only when , that is for . Here , so and : the state has turned past all the way to .
- : The round does change the state: it turns it by , from to , and .
- : That is , the bad part before the round. After the round the angle is , and the good chance is .
5 / 13 · Worked example
Worked example: how many rounds?
The best number of rounds makes as close to as possible: is the whole number nearest to . Keep a calculator at hand for .
Worked example
An algorithm that succeeds once in a hundred runs
First , worked for you; then , which you finish.
Angle
, so .
Rounds
, so . The state ends at .
Chance
. With the state would pass , to , and the chance would drop to .
Cost
In all, and run times, and runs 7 times. Rerunning needs 100 runs on average, and 15 reruns succeed with chance only .
Your turn: rounds
Now : , so .
Your turn
With , how many rounds of make a good outcome most likely?
Hints
- Which puts closest to ?
- .
Show the answer
Answer:
, so : the state ends at .
Common slips
- : Four rounds take the state to , past , where the chance is . Remember the : the state already starts at , so three rounds reach .
- : 25 is , the average number of reruns of . Rounds of grow like : the state needs to turn only about , in steps of .
- : Two rounds reach , with chance . One more round gets much closer to .
Your turn: chance
Your turn
With rounds and , what is the chance of a good outcome? (Two or three decimal places.)
Hints
- The angle after rounds is .
- ; square its sine.
Show the answer
Answer:
, and . Rerunning the same times would succeed with chance .
Common slips
- : That is , the chance before any round. After three rounds the angle is .
- : That is the chance after two rounds, at . Three rounds reach .
- : That is the chance after four rounds, at . Three rounds reach .
One more, fully worked, with .
Another worked example
Another example: p = 1/9
Angle
, so .
Rounds
, so . The state ends at : a little past , but closer than .
Chance
, against for . Rerunning five times would succeed with chance .
6 / 13 · Practice
Build Q in code
In code, of a rotation is the same rotation with the opposite angle, and the minus sign in front of needs no gate. So one round of is the six gate calls from the prediction program. To apply several rounds, write the round once as a function and call it in a loop.
The same recipe works on any number of qubits. For a circuit a, Qiskit’s a.inverse() builds : the gates in reverse order, each one inverted. is an on every qubit, a controlled by all the others, and the gates again. The example under the exercise does this on three qubits.
Check yourself
Now take , so with , and . Call good. Then 4 rounds of reach . Complete the program: write one round of in q_round, then apply it 4 times, so that the qubit ends in (up to a global phase).
from qiskit import QuantumCircuit
from math import pi
qc = QuantumCircuit(1)
qc.ry(pi / 9, 0) # A
def q_round(qc):
# one round of Q: S_good, then A^-1, then S0, then A
pass
# apply q_round 4 times hereWrite the program in the app’s code editor (Python with Qiskit’s circuit methods), run it, and check it.
Hints
- Copy the six gate calls of one round from the prediction program, with the angle changed to
pi / 9. - Put them inside
q_round(indented by four spaces, replacingpass), then callq_round(qc)4 times, for example infor i in range(4):.
Show the answer
One program that works:
from qiskit import QuantumCircuit
from math import pi
qc = QuantumCircuit(1)
qc.ry(pi / 9, 0) # A
def q_round(qc):
qc.z(0) # S_good: flip the sign of |1>
qc.ry(-pi / 9, 0) # A^-1
qc.x(0) # S0 = X Z X: flip the sign of |0>
qc.z(0)
qc.x(0)
qc.ry(pi / 9, 0) # A
for i in range(4):
q_round(qc)Each round turns the state by , so after 4 rounds it sits at from : the state is , and the sign is a global phase. (On one qubit, plain in place of also passes, since differs only by a global sign. With more qubits, and are different mirrors.)
One round is , then , then , then ; the minus sign in front of is a global phase and needs no gate. Apply that round 4 times after the first . The angle goes , so the final state is .
7 / 13 · Learn
What it costs
For small , in radians, and the best number of rounds is close to
Each round runs once, once and once. Rerunning needs runs on average. For that is about 785 rounds against a million runs: a square-root saving, the same one Grover search gets. With and it reads .
The chance is not monotonic in . Past the best the state turns beyond , and the chance falls again.
For : the bars show after rounds, best at with 99.5%. The dots show rerunning as often as rounds use and , that is times: 15 runs give only 14%. Past the bars shrink, because the state has turned past .
Check yourself
An algorithm succeeds with probability . About how many rounds of make a good outcome nearly certain?
Hints
- For small , in radians.
- Rounds .
Show the answer
Answer:
, so radians and about rounds; the exact rule gives , with success over 99.9%. Rerunning would need about 10,000 runs on average.
Common slips
- : 10,000 is , the average number of reruns of . Rounds of grow like instead.
- : is the right scale, but the state only has to turn about in steps of : that is about rounds.
- : 157 counts every use of and , in all. The question asks for rounds of , each of which uses both.
8 / 13 · Learn
When you don’t know p
Everything so far needed to choose . Often you don’t know it: you don’t know how many items are marked, or how often your algorithm succeeds. A wrong guess is costly, because the chance oscillates: too many rounds can be worse than none. The search in the second prequestion shows how badly it can go.
The fix, from Boyer, Brassard, Høyer and Tapp (1998), is to choose at random. Fix a bound and pick uniformly from . Averaged over , the chance of success is
Why about : the angles spread around the circle, and averages over a full turn. The second term shrinks as grows. Since , as soon as that term is at most , so the average is at least .
For , the average success when is picked at random below . Once passes , the average is at least , and it settles near . The dashed curve, , is the floor the formula guarantees.
Check yourself
Take , so . You pick at random from (so ), run and rounds of , and measure. What is the chance of a good outcome?
Hints
- List the angles for .
- : square each sine, then average.
Show the answer
Answer:
The angles are , with chances . Their average is . The formula agrees: .
Common slips
- : One round, , gives certainty, but you pick at random: three of the four choices end at , or , each with chance .
- : Three of the four choices give , but gives 1. The chance is the average, .
- : is where the average settles for large . For , average the four chances: .
The full method grows as it goes, so it never needs :
- Start with .
- Pick at random from . Run , apply times, measure, and check the result.
- If it is good, stop. If not, multiply by a fixed factor (the paper uses ) and go back to step 2.
While is small the tries are cheap. Once passes , each try succeeds with chance at least . Added up, the expected number of rounds is of order , which for search is order : the same scaling as knowing , with a larger constant. If nothing is marked, nothing can succeed, so you stop once the total passes a fixed multiple of and report “none”. Had there been a marked item, it would very likely have turned up by then.
Check yourself
Why does the method start with and grow it by after each failure, instead of choosing a huge from the start?
- AA huge makes the average success drop toward 0
- BA huge makes huge too, which wastes rounds whenever turns out to be large
- CBecause has to hit the best number of rounds exactly
- D must stay below
Show the answer
Answer: B. A huge makes huge too, which wastes rounds whenever turns out to be large
Each try costs about rounds, and is typically about . Growing by a constant factor from 1 means reaches having spent only a constant multiple of that many rounds, whatever is. A huge starting would spend order rounds per try even when is large and a round or two would do.
Why not the others
- A. For large the average settles near , not 0: the second term of the formula shrinks like . The trouble is cost: a random below a huge is usually huge, and each round costs a run of and .
- C. No exact is needed. Once is large enough, a random below it succeeds with chance about on average.
- D. It is the other way round: the guarantee of at least starts once passes . Growing step by step reaches that point without overshooting it by more than a constant factor.
9 / 13 · Learn
The fine print
Grover search is often described as searching a database in steps. Three details limit what that means.
- The data has to get in. The oracle must answer “is item marked?” for a superposition of positions , so the whole list must sit in a memory that a circuit can query in superposition. Writing items into it takes order steps, as many as a classical computer needs to scan the list once.
- The oracle is a circuit. Every query runs a circuit that computes the check, and it costs gates, often many.
- The gain is quadratic. against is a large saving for large , but nothing like the exponential gap of Simon’s algorithm in Lesson 15, and the slower, error-corrected gates of a real machine eat into it.
The speed-up pays off when there is no list to load: the items are all -bit strings, and being good is a property a circuit can check. Lesson 18 builds such an oracle.
Check yourself
A company keeps a billion () customer records, unsorted, on ordinary disks. It wants to find the one record with a given ID, once. Which statement is accurate?
- AA quantum computer finds it in about 30 queries, one per bit of the record’s position
- BA quantum search would not help: putting the records into a quantum memory takes about steps, as long as one classical scan
- CGrover search finds it with about queries, so it is far faster than a scan
- DGrover search needs the records sorted by ID first; after that it is fast
Show the answer
Answer: B. A quantum search would not help: putting the records into a quantum memory takes about steps, as long as one classical scan
The count assumes an oracle that answers for a superposition of positions. For stored data that means a quantum memory holding all records, and filling it costs order steps. For a one-off lookup a classical scan costs no more than that.
Why not the others
- A. That would be an exponential speed-up, and unstructured search has none: every quantum method needs on the order of queries. And the cost of loading the data comes on top.
- C. The query count is right, but each query needs the records in a memory that a circuit can address in superposition. Writing records into it takes about steps, the cost of the scan you hoped to avoid.
- D. Grover search needs no order at all; that is its point. And once the records are sorted, a classical binary search takes about steps. The obstacle is getting the data into a quantum memory, which costs order .
Could a cleverer quantum algorithm beat ? No. Bennett, Bernstein, Brassard and Vazirani proved in 1997 that any quantum algorithm needs on the order of queries to find a marked item among when nothing else is known about where it is; their paper is listed under Go further. So Grover search, and amplitude amplification with its , are optimal up to a constant factor: a square root is all that interference can buy for unstructured search.
Check yourself
Someone claims a quantum algorithm that finds the one marked item among items, with nothing known about where it is, using 1,000 queries. What should you think?
- APlausible, if it picks the number of rounds at random
- BPlausible, if it applies about 1,000 times
- CIt can’t be right as stated: every quantum method needs on the order of , about 34 million, queries
- DPlausible: quantum algorithms are exponentially faster than classical ones
Show the answer
Answer: C. It can’t be right as stated: every quantum method needs on the order of , about 34 million, queries
For unstructured search every quantum algorithm needs order queries, and . Grover’s is within a constant factor of that limit. A method using 1,000 queries must be exploiting structure that the problem, as stated, doesn’t have.
Why not the others
- A. Picking at random handles an unknown number of marked items. It costs a constant factor more than knowing that number, never less.
- B. Every round of is a query: it uses once. With one marked item among , about rounds are needed.
- D. Some problems have exponential quantum speed-ups, but unstructured search is proven not to: any quantum algorithm needs order queries, here about .
10 / 13 · Practice
Practice
Three items, each with new numbers when it comes back. Hints are there if you need them.
Check yourself
An algorithm succeeds with probability . What is the chance of a good outcome after and 2 rounds of ? (Two or three decimal places.)
Hints
- Find from .
- After rounds the angle is ; the chance is the square of its sine.
- Here and .
Show the answer
Answer:
, so 2 rounds reach , and .
gives . Each round adds to the angle, so after 2 rounds it is . The chance of a good outcome is .
Common slips
- : That uses the angle . The state starts at , so after 2 rounds it is at .
- : That turns by per round. Two reflections whose mirrors meet at turn the state by .
- : That grows the amplitude in a straight line, , which only holds while the angle is small. Use itself.
- : That is the chance before any round.
Check yourself
Grover search over items, of which are marked. About how many iterations make finding a marked item most likely?
Hints
- Grover is amplitude amplification with . For small , in radians.
- Iterations .
Show the answer
Answer:
, so about iterations. The exact rule, nearest to , gives , with success chance over 99.9%.
Here , so and radians. The best makes closest to : , which rounds to 50. The quick estimate is within one of it.
Common slips
- : sets the scale, but it is not the count. Each iteration turns the state by radians, and it only needs to turn about : that takes about iterations.
- : 4,096 is , the average number of random guesses. Iterations grow like the square root of that.
- : 201 is the count for one marked item. With marked items is times larger, so 4 times fewer iterations are needed.
Check yourself
You don’t know ; in fact , so . You pick at random from to (so ), run and rounds of , and measure. What is the chance of a good outcome?
Hints
- List the angles for each allowed .
- The angles are . Square each sine, then average the 2 values.
Show the answer
Answer:
The angles give chances . Each is equally likely, so the chance is their average, .
With , the allowed end at the angles . Their chances are . Picking uniformly at random, the chance of a good outcome is the average of these 2 numbers: .
Common slips
- : is where the average settles when is large. For , average the 2 chances themselves: .
- : That is the best single . Here is random, so every choice from 0 to 1 counts equally: average the 2 chances.
- : That is alone: no rounds at all. Average over all the allowed .
11 / 13 · Explain
Explain it
Explain it
Each piece of only flips signs or undoes . Explain why applying to still raises the chance of a good outcome, and why too many rounds lower it again.
Show a model answer
Write with . In the plane of these two states, flips the good part, which is a reflection in the line, and is a reflection in the line of . The two lines meet at angle , and two reflections make a rotation by twice that angle: each round turns the state toward . After rounds the angle is and the chance is , which grows until the angle reaches . More rounds carry the state past , and the chance falls again.
A good answer covers
- is a reflection that flips the good part, and is a reflection in the line of
- Two reflections make a rotation by toward , where
- After rounds the chance is
- Past the state turns away from , so the chance falls
12 / 13 · Mastery check
Mastery check
Check yourself
An algorithm gives a good answer with probability , and you can check any answer. Rerunning until it succeeds takes about runs, so if becomes a million times smaller, rerunning costs a million times more. This lesson’s method replaces rerunning. If becomes a million times smaller, how does the cost of that method change?
- AIt grows a million times too: nothing beats rerunning
- BIt grows about 1,000 times
- CIt grows by a fixed amount: about 20 more rounds
- DIt doesn’t change: one quantum run checks every answer at once
Show the answer
Answer: B. It grows about 1,000 times
Each round turns the state by , where , and it has to turn through about . For small , radians, so it takes about rounds: a million times smaller means 1,000 times more rounds.
Why not the others
- A. Rerunning grows like , but it is not the only option. Amplitude amplification turns the state by a fixed angle per round, and the number of rounds grows like : a million times smaller costs only 1,000 times more.
- C. That would be a logarithmic cost, like halving an interval 20 times. Amplitude amplification gains a square root, not more: a million times smaller needs about 1,000 times as many rounds, and no method does better in general.
- D. A run on a superposition still ends in one measurement with one random result. The good results have to be made likely first, and that takes rounds: about of them.
Check yourself
Let , and let be any state orthogonal to . What does do to ?
- ATurns it toward the good states
- BLeaves it unchanged
- CMultiplies it by
- DSends it to
Show the answer
Answer: C. Multiplies it by
is orthogonal to , so leaves it alone, returns , and the leading minus sign gives . With , that makes , the mirror in the line of .
Why not the others
- A. Half of only reflects: it fixes the line of and flips everything orthogonal to it. A turn toward the good states needs both halves of .
- B. is orthogonal to , so leaves it alone, and brings back . The minus sign in front then flips it. It is that stays unchanged.
- D. alone sends , not , to , and undoes that at the end. The net effect on is a sign: .
Check yourself
An algorithm succeeds with probability . You run and then one round of . What is the chance of a good outcome now? (A fraction, or three decimal places.)
Hints
- Find from .
- One round takes the angle from to ; the chance is .
Show the answer
Answer:
, so and . In general one round gives , from .
From , . One round of turns the state by , from to . The chance of a good outcome is .
Common slips
- : That is , the chance before the round. One round turns the state from to .
- : One round does not add twice more. acts on amplitudes: it turns the state by , and the chance is .
- : That is . The state starts at angle , so one turn of takes it to .
Check yourself
A Grover search over items is tuned for one marked item: it makes 17 iterations, which find that item with probability 99.9%. Unknown to you, 4 items are marked. With the same 17 iterations, what is the chance of finding a marked item?
- AOver 99.9%: more marked items are easier to find
- BAbout 99.9%: the number of marked items doesn’t matter
- CAbout 0.8%, the chance of a random guess
- DAbout 0.2%, worse than a random guess
Show the answer
Answer: D. About 0.2%, worse than a random guess
With one marked item , so , and 17 iterations reach . With 4 marked items doubles: , and the same 17 iterations reach about , past at and nearly round to the unmarked side. The chance is , while a random guess gets .
Why not the others
- A. More marked items make each iteration turn the state further: is twice . 17 iterations then carry the state past the marked items, so more turning is not better here.
- B. The angle of each iteration depends on how many items are marked. With 4 of them is about twice as large, so 17 iterations turn the state about twice as far as planned.
- C. The iterations are not wasted: they move the state, just too far. It ends close to the unmarked states, and the chance, 0.2%, is below even a random guess.
Check yourself
Grover search over items, of which is marked. About how many iterations make finding a marked item most likely?
Hints
- Grover is amplitude amplification with . For small , in radians.
- Iterations .
Show the answer
Answer:
, so about iterations. The exact rule, nearest to , gives , with success chance over 99.9%.
Here , so and radians. The best makes closest to : , which rounds to 201. The quick estimate is within one of it.
Common slips
- : sets the scale, but it is not the count. Each iteration turns the state by radians, and it only needs to turn about : that takes about iterations.
- : 65,536 is , the average number of random guesses. Iterations grow like the square root of that.
- : 32,768 is , about how many items a classical search checks on average. Grover needs about iterations.
Check yourself
You don’t know ; in fact , so . You pick at random from to (so ), run and rounds of , and measure. What is the chance of a good outcome?
Hints
- List the angles for each allowed .
- The angles are . Square each sine, then average the 4 values.
Show the answer
Answer:
The angles give chances . Each is equally likely, so the chance is their average, .
With , the allowed end at the angles . Their chances are . Picking uniformly at random, the chance of a good outcome is the average of these 4 numbers: .
Common slips
- : is where the average settles when is large. For , average the 4 chances themselves: .
- : That is the best single . Here is random, so every choice from 0 to 3 counts equally: average the 4 chances.
- : That is alone: no rounds at all. Average over all the allowed .
Check yourself
Someone claims a quantum algorithm that finds the one marked item among items, with nothing known about where it is, using 1,000 queries. What should you think?
- APlausible, if it applies about 1,000 times
- BIt can’t be right as stated: every quantum method needs on the order of , about a million, queries
- CPlausible, if it picks the number of rounds at random
- DPlausible: quantum algorithms are exponentially faster than classical ones
Show the answer
Answer: B. It can’t be right as stated: every quantum method needs on the order of , about a million, queries
For unstructured search every quantum algorithm needs order queries, and . Grover’s is within a constant factor of that limit. A method using 1,000 queries must be exploiting structure that the problem, as stated, doesn’t have.
Why not the others
- A. Every round of is a query: it uses once. With one marked item among , about rounds are needed.
- C. Picking at random handles an unknown number of marked items. It costs a constant factor more than knowing that number, never less.
- D. Some problems have exponential quantum speed-ups, but unstructured search is proven not to: any quantum algorithm needs order queries, here about .
13 / 13 · Recap
Recap
From memory
Before reading the summary, write down what you remember. Pulling it back from memory is what makes it last.
Write the iterate and say what each piece does.
Show the key points
- ; read right to left, so acts first
- flips the sign of the good states; flips the sign of
- undoes ; the minus sign is a global phase
- Grover search is the case
How many rounds should you run, what is the success chance, and how does that compare with rerunning ?
Show the key points
- ; after rounds the chance is
- nearest , about ; more rounds overshoot
- Rerunning needs about runs
What do you do when is unknown, and what does Grover search not give you?
Show the key points
- Pick at random below , and grow by a factor such as after each failure
- Once a try succeeds with chance at least ; the expected cost stays of order
- Stored data must be loaded (order ), the oracle is a circuit, and order queries is the proven minimum
Key ideas
Amplitude amplification: for any algorithm without measurements and any way to recognize good outcomes, turns toward the good states.
Two reflections make one rotation: with , rounds succeed with chance . For , one round gives certainty.
About rounds instead of about reruns. Grover search is the case , .
Unknown : pick at random below a bound that grows by a constant factor. The expected cost stays of order , and if order queries find nothing, report “none”.
Grover search is no fast database lookup: loading costs order , the oracle is a circuit, and order queries is the proven minimum for unstructured search.
Go further
Free resources for when you want more than this lesson covers.
- Amplitude amplificationWikipedia · Article
A short reference page that derives the general algorithm with good and bad subspaces and shows Grover search as a special case.
- Quantum Amplitude Amplification and EstimationBrassard, Høyer, Mosca and Tapp · Article
The research paper behind this lesson’s iterate Q, with its rotation analysis and the case of an unknown success chance.
- Tight bounds on quantum searchingBoyer, Brassard, Høyer and Tapp · Article
The 1998 paper with the random-k method for an unknown number of solutions, readable with this lesson in hand.
- Strengths and Weaknesses of Quantum ComputingBennett, Bernstein, Brassard and Vazirani · Article
The 1997 paper proving that no quantum algorithm searches without structure in far fewer than √N queries.