Lesson 9: Parallelism, Deutsch and Deutsch–Jozsa
One query, one global answer: phase kickback and interference
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 / 15 · Learn
Before you start
A measurement returns one bit per qubit (Lesson 1), and a relative phase becomes visible only after a gate such as makes the branches interfere (Lessons 4 and 5). This lesson puts both facts to work in the first quantum algorithms, with the phase kickback of Lessons 6 and 7 as the key step.
Part A: the oracle, quantum parallelism and Deutsch’s algorithm. Part B: input bits, the Deutsch–Jozsa algorithm, and how many queries each method needs.
By the end of this lesson you can:
- apply to basis states and to superpositions;
- say what one measurement after a query on a superposition reveals, and what it doesn’t;
- derive phase kickback and trace Deutsch’s algorithm for all four one-bit functions;
- compute and the amplitude in Deutsch–Jozsa;
- compare query counts: quantum, deterministic classical and randomized classical.
Check yourself
A warm-up: make a guess before reading on. The lesson comes back to it.
A quantum computer applies once to a superposition of all eight 3-bit inputs, producing . Then every qubit is measured in the 0/1 basis. What does this one run tell you about ?
- AAll eight values : the whole table of
- BNothing: measuring a superposition gives meaningless random bits
- COnly , because the inputs started in
- DThe value at one input , chosen at random
Show the answer
Answer: D. The value at one input , chosen at random
Each branch has amplitude . The measurement picks one branch at random, with probability each, and returns its input and its value: one per run, which is no more than one classical query gives.
Why not the others
- A. The state involves all eight values, but a 0/1 measurement of 4 qubits returns 4 bits: one input and its value . The other branches are gone once you have measured.
- B. The bits are not meaningless. Every branch is , so in every result the last bit equals of the first ones: you learn one genuine value.
- C. Every input has the same amplitude, , so the measured is random: turns up only one time in 8.
Check yourself
A warm-up: make a guess before reading on. The lesson comes back to it.
A black box computes on 3-bit strings (eight inputs). You are promised that is either constant or balanced (0 on exactly 4 inputs and 1 on the other 4). Querying one input at a time, and needing to be certain, how many queries might you need in the worst case?
- A
- B
- C
- D
Show the answer
Answer: C.
In the worst case the first 4 answers agree, which a balanced allows. Query number 5 decides: for .
Why not the others
- A. Two queries settle it only if they disagree. If they agree, a balanced is still possible: 4 inputs share each value.
- B. The count depends on the number of inputs, not on the number of bits in . A balanced can give the same value on any 4 inputs, so 4 agreeing answers prove nothing.
- D. You never need all 8. A balanced has only 4 inputs of each value, so once 5 answers agree, must be constant.
2 / 15 · Learn
Part A · The oracle and quantum parallelism
Part A: the oracle, what a query on a superposition gives you, and Deutsch’s algorithm.
A function from one bit to one bit is either constant () or balanced (). To use in a circuit you need a gate, and a gate that simply replaced by fails for a constant : both inputs would land on one output, which no reversible gate allows. The fix is the Toffoli trick from Lesson 6: keep the input, and XOR the value into a second qubit,
Here is called the data register and the target. Applying twice gives back , so undoes itself: it only permutes the basis states.
Check yourself
For , so and , what is ?
- A
- B
- C
- D
Show the answer
Answer: A.
, so the target becomes , and the data qubit is untouched: . The truth table above shows the same row.
Why not the others
- B. That replaces by . On basis inputs never changes the data qubit; the value goes into the target, by XOR.
- C. That writes into the target, replacing . adds it mod 2 instead: . Overwriting would erase , and could not be undone.
- D. Only the target can change on a basis input. The data qubit stays , and the target becomes .
Now give a superposition. With the data qubit in and the target in , acts on each branch separately (linearity):
One use of , and the state involves both and . With data qubits, each in , there are branches, and one use of gives . This is called quantum parallelism. Whether you can get the values out is the next question.
Check yourself
Let . Enter as four amplitudes, to (data qubit first).
Hints
- Apply to each branch, and , separately.
- , with and .
Show the answer
Answer:
Branch by branch: and . So the result is , which is the Bell state : the data and the target are now entangled.
3 / 15 · Explore
Part A · What one run reveals
Predict, then see
Two data qubits, each in , a target in , and one use of give
You measure all three qubits in the 0/1 basis. Then you measure the same three qubits again, without preparing anything new. What do the two results show?
- AAll four pairs at once; the second measurement adds nothing new
- BTwo different pairs : each measurement reads out another branch
- CTwo random 3-bit strings with no link to
- DThe same pair both times, with random
Why did the second measurement repeat the first, and what does it cost to see another pair ? A sentence or two is enough.
Show what happens
What happens: D. The same pair both times, with random
Each measurement returns one branch : a random (probability each) with its correct value. Measuring again repeats it, because the measurement left the register in that basis state. Learning more needs fresh copies, each costing another use of : one value per query, as on a classical computer, except that you don’t get to choose .
Why not the others
- A. Three qubits measured in the 0/1 basis give three bits: two for and one for . The state involves all four values, but a measurement returns a single branch, picked at random.
- B. With all four branches in the state, it seems a second look should find another one. But in the widget the second result repeated the first: one measurement keeps one branch and discards the rest.
- C. The bits are not noise. In every result the last bit equals of the first two, because every branch is . Check any result in the widget against the values listed above it.
Why not just read off the amplitudes?
The circles show the amplitudes because this is a simulation. A real register offers no such readout. The only access is measurement, and a 0/1-basis measurement of three qubits returns three bits (Lesson 6). Estimating amplitudes from statistics takes many fresh copies, and so many uses of .
Check yourself
Three data qubits, each in , and a target in ; one use of ; then all four qubits are measured in the 0/1 basis. What is the probability that this run tells you ?
Hints
- What decides which value of the run shows?
- The data register gives each of its eight strings with the same probability.
Show the answer
Answer:
The data register gives each of the eight inputs with probability , and the target then shows for that input. So appears with probability .
Common slips
- : That assumes the run reveals every value. The measurement returns one branch , and is one of eight equally likely inputs.
- : That treats all four measured bits as random. Only the three data bits are: once is found, the target bit is for certain. So the chance is that of finding , which is .
- : Either you learn or you don’t, but the two cases are not equally likely. You learn it only when the data register gives , one of eight equally likely results.
4 / 15 · Learn
Part A · Phase kickback
Change one thing: put the target in . If , leaves alone. If , it flips the target, and flipping swaps the two terms of : . Both cases in one line:
The target comes out unchanged, and the value has become a sign on the data branch. On a basis state that sign is a global phase. On a superposition each branch gets its own sign, a relative phase. This is the phase kickback you met with CNOT in Lessons 6 and 7: CNOT is for .
Check yourself
Let , so and . What is ?
- A
- B: the data qubit acts like a control, and controls don’t change
- C: the target flips
- D
Hints
- Write as two branches and apply to each.
- A branch gains exactly when .
Show the answer
Answer: A.
Branch by branch: gives and gives . Together . The overall minus is a global phase; the relative sign between the branches is what turned into .
Why not the others
- B. “The control never changes” holds only for basis inputs. Split into its branches: the branch has and picks up , the branch doesn’t. A minus sign on just one branch turns into (up to an overall sign).
- C. Flipping doesn’t give : swaps the two terms of and so gives . The target keeps its state; the sign lands on the data branch.
- D. That would need both branches to pick up , which happens for . Here only the branch has , so the two branches end with opposite signs.
5 / 15 · Learn
Part A · Deutsch’s algorithm
Deutsch’s problem: is a one-bit constant or balanced? A classical computer has to evaluate twice. Deutsch’s circuit uses once. Follow the state:
- , the input;
- on both qubits gives ;
- then acts with kickback on each branch:
Think of each input as carrying a chip, or . If is constant the two chips match, and the data qubit is . If is balanced they differ, and it is .
Check yourself
For which functions is the data qubit in (up to an overall sign) right after ?
Select all that apply.
- A
- B
- C
- D
Hints
- Find the two chips and for each function.
- Matching chips leave ; different chips give .
Show the answer
Answers: A. ; D.
The data qubit is exactly when the chips differ, that is when : the two balanced functions (giving ) and (giving ).
Why not the others
- B. With both chips are , so the data qubit stays .
- C. With both chips are : the data qubit is . An overall sign is a global phase, so this is still , not .
6 / 15 · Learn
Part A · The last Hadamard
The last acts on the data qubit only. It turns into and into :
In chip terms, the data qubit’s amplitude is the average of the two chips, and its amplitude is half their difference. Matching chips add on and cancel on ; opposite chips do the reverse. So a 0/1-basis measurement of the top qubit gives with certainty: 0 for constant, 1 for balanced. One query settles a question that no single classical evaluation can, and yet you learn neither nor .
Check yourself
Deutsch’s algorithm runs with . What does the 0/1-basis measurement of the top qubit give?
- A1, with certainty
- B0, with certainty
- C first; a second measurement then gives
- D0 or 1, each with probability : Hadamards randomize
Show the answer
Answer: A. 1, with certainty
The chips are and . They differ, so after the data qubit is , and the last makes it . The measurement gives : balanced.
Why not the others
- B. 0 is the constant answer. Here and , so the chips are and : they cancel on and add on .
- C. The circuit never makes or readable on its own. Kickback turns them into two signs, and the last combines the signs into the single bit . Measuring again just repeats that bit.
- D. A Hadamard can also undo randomness: exactly. After the query the data qubit is , a definite state, and the last turns it into . Nothing is left to chance.
Check yourself
After Deutsch’s circuit someone measures the bottom (target) qubit in the 0/1 basis. What do they get?
- A, because writes into the target
- B0 or 1 with probability each, whatever is
- C, the value at the first input
- D1, because the target started in
Show the answer
Answer: B. 0 or 1 with probability each, whatever is
The target is at the end for every , so its 0/1 measurement gives 0 or 1 with probability each. The answer is in the top qubit.
Why not the others
- A. With the target in , only multiplies the target by , so it stays for every . A 0/1 measurement of is a fair coin, with no information about .
- C. No value of is stored in the target. It is for every ; the effect of is a sign on the data branches.
- D. The first turned the target’s into , and it stays to the end. Measured in the 0/1 basis, gives 0 or 1 with probability each.
7 / 15 · Worked example
Part A · Worked example: all four functions
Enter states as four amplitudes, to , top qubit first. These steps want the exact vector, signs included, even where an overall sign would be a harmless global phase.
Worked example
The two balanced functions
Every run starts from the same . First , worked for you; then , which you do.
Query
Take . , so the terms are untouched. , so in the terms the target flips: and swap amplitudes, . So
Chips: for , for .
Last H
, so . With chips: the top amplitude is and the top amplitude is . The measurement gives .
Your turn: query
Now : and . Start again from .
Your turn
Run Deutsch’s algorithm with . Enter , the state right after , as four amplitudes. Give the exact vector, signs included.
Hints
- Which branches have ?
- In those branches the target flips, and : the branch changes sign, the target doesn’t.
- Here and . Multiply each branch of by its chip.
Show the answer
Answer:
Chips: and . So .
Your turn: last H
Your turn
Run Deutsch’s algorithm with . Enter , the state after the final , as four amplitudes. Give the exact vector, signs included.
Hints
- Find first: which sign does each branch carry?
- Then apply to the top qubit only: , .
- Here .
Show the answer
Answer:
Chips: and , so . on the top qubit gives . The top qubit reads : balanced.
One more, fully worked, with a constant function.
Another worked example
Another example: a constant function
Query
Take . No branch has , so does nothing: . Both chips are .
Last H
, so . With chips: on the top and on the top .
Read out
The measurement gives 0: constant. For both chips are , which gives : the same physical state with a global sign, and the same reading.
Check yourself
Run Deutsch’s algorithm with . Enter , the state after the final , as four amplitudes. Give the exact vector, signs included.
Hints
- Find first: which sign does each branch carry?
- Then apply to the top qubit only: , .
- Here .
Show the answer
Answer:
Chips: and , so . on the top qubit gives . The top qubit reads : balanced.
8 / 15 · Learn
Part B · Hadamards on n qubits
Part B: input bits, the Deutsch–Jozsa algorithm, and how many queries each method needs.
means a Hadamard on each of qubits. On every qubit becomes , and multiplying out the product gives each -bit string exactly once:
For that is . So gates prepare an equal superposition of strings, each with amplitude , so that the probabilities add up to 1. is also called the Walsh–Hadamard transform.
Check yourself
What is the amplitude of in ?
Hints
- How many strings appear, and do they all have the same amplitude?
- Each qubit contributes a factor .
Show the answer
Answer:
has 8 terms, each with amplitude . That includes .
Common slips
- : is the probability of each string. The amplitude is its square root, , so that eight probabilities of add up to 1.
- : Three qubits don’t give three terms: the product of three factors has terms, each with amplitude .
- : That shares the probability among three strings. There are strings, so each amplitude is .
- : is the amplitude for two qubits. Each extra qubit multiplies by another : .
Other inputs give signs. For one qubit, and : the term gets a minus sign exactly when the input and are both 1. Multiply the factors and the signs multiply:
Here is the dot product mod 2. So is negative when and share an odd number of 1s. Check with : , negative where ends in 1.
Refresher: Bits, XOR and bit strings The dot product mod 2, sums over bit strings and signs , with practice.
Check yourself
Enter as four amplitudes.
Hints
- Which bit of is 1?
- With , : minus exactly where the first bit of is 1.
Show the answer
Answer:
, so , and the sign is minus exactly where starts with 1: . That is , as should be.
9 / 15 · Learn
Part B · The Deutsch–Jozsa algorithm
Now takes bits to one bit, and you are promised that it is constant (the same value on all inputs) or balanced (0 on exactly half of them, 1 on the other half). Which is it? The circuit is Deutsch’s with a wider data register: qubits in and a target in ; on every qubit; one ; then on the data and a 0/1-basis measurement of the data. After the query, kickback has put a chip on every input:
Check yourself
Let and , , , , a balanced function. Enter the data register’s part of , that is , as four amplitudes.
Hints
- What is the chip for each of the four inputs?
- Each amplitude is times its chip.
Show the answer
Answer:
Chips : . So the data register is , which happens to be .
The last sends each to . Collect the terms for one output ; its amplitude is
For every is 0, so the amplitude of is simply the average of the chips. If is constant, all chips are equal, the average is , and the measurement gives all zeros with certainty. If is balanced, half the chips are and half , the average is 0, and all zeros never appears. The rule: all zeros means constant; anything else means balanced.
Check yourself
Deutsch–Jozsa with and some balanced . What is the probability that the 0/1-basis measurement of the data register gives ?
Hints
- What is the amplitude in terms of the chips?
- It is the average of the eight chips . How many are for a balanced ?
Show the answer
Answer:
The amplitude is for every balanced , so . That is why the read-out rule never fails.
Common slips
- : That treats the last Hadamards as spreading the probability evenly over the eight strings. They add the eight chips into the amplitude, and four s cancel four s exactly.
- : Half the inputs have , but probabilities don’t follow that count. The amplitude is the average of the chips, .
- : Square the average of the chips, not one chip over 8. For a balanced the average is .
- : All zeros with certainty is what a constant gives, when all eight chips are equal. For a balanced , four chips and four chips cancel on : its amplitude is .
10 / 15 · Learn
Part B · Where a balanced f sends the amplitude
For a balanced , the probability that leaves has to land on other strings, and which ones depends on . A tidy family is for a fixed string (such an is balanced). Its chips are exactly the signs gives when it acts on . Since undoes itself, the last Hadamards turn the data register back into , with certainty. For and , the last bit of , that string is .
Check yourself
Deutsch–Jozsa with and . What does the 0/1-basis measurement of the two data qubits give?
- A, with certainty
- B, with certainty
- CEach of the four strings with probability
- D or , the inputs where
Hint
- for which string ?
Show the answer
Answer: B. , with certainty
, so and the output is with certainty. Check: for , for every , so all four signs are and the amplitude is 1.
Why not the others
- A. All zeros means constant, and is balanced: , . Its chips cancel on .
- C. The last Hadamards don’t spread the amplitude out evenly. For each they add four signed terms; here the terms add up fully for one string and cancel for the other three.
- D. The output is not a list of inputs. It is the string where the signs all agree. For they are , which cancel.
A preview beyond this course
Finding the hidden string in with one query is called the Bernstein–Vazirani problem. A classical computer needs queries for it, one per bit of . This course doesn’t cover it, but it uses exactly the circuit you just ran.
11 / 15 · Learn
Part B · Counting queries
A classical method that must be certain can be unlucky. A balanced gives the same value on half its inputs, so the first answers can all agree. One more query settles it: queries in the worst case. Deutsch–Jozsa uses once, whatever is. For , Deutsch’s problem, that is 2 against 1; for it is 513 against 1.
Check yourself
For , how many queries does a deterministic classical method need in the worst case to be certain?
Hints
- How many inputs can share the same value when is balanced?
- There are inputs, half of them with each value.
Show the answer
Answer:
A balanced has inputs of each value, so 32 answers can agree; the 33rd settles it: .
Common slips
- : You never need all inputs. Half of them, 32, can share a value under a balanced , so 33 agreeing answers already prove that is constant.
- : Thirty-two agreeing answers are still possible for a balanced : it has 32 inputs of each value. The 33rd query is the one that decides.
- : The count depends on the number of inputs, , not on the number of bits. Up to 32 answers can agree under a balanced .
What changes if a small chance of error is allowed? Query inputs chosen at random and answer “constant” if all values agree, “balanced” otherwise. A constant is never misjudged. A balanced fools you only if all values agree. For independent random inputs each value is 0 or 1 with probability , so all agree with probability
(picking distinct inputs only lowers it). This does not depend on : eleven queries keep the error below 1 in 1000 for any . Deutsch–Jozsa’s exponential advantage holds only against classical methods that must never err.
Check yourself
You use the random method with queries on a balanced . What is the probability that it wrongly answers “constant”?
Hints
- Which outcomes of the four queries lead to the answer “constant”?
- All 0s, or all 1s. Each has probability .
Show the answer
Answer:
The method says “constant” when all four values agree: all 0s or all 1s, each with probability . So the error is .
Common slips
- : That is the chance that all four values are 0. They could also all be 1, which fools you just as well, so double it: .
- : That is the chance of the right answer, balanced. The error happens when all four values agree: .
- : One query gives 0 or 1 with probability , but the error needs all four to agree, and each extra query halves that chance: .
Check yourself
A headline reads: “Deutsch–Jozsa shows that a quantum computer beats every classical computer exponentially.” Take . Which verdict is accurate?
- AExaggerated: the gain is exponential only against classical methods that must never err
- BFalse: Deutsch–Jozsa needs many runs too, so it has no advantage
- CFalse: a careful classical method needs only 50 queries, one per bit
- DAccurate: every classical method needs queries
Hint
- How many queries does the random method need to push its error below , and does that number depend on ?
Show the answer
Answer: A. Exaggerated: the gain is exponential only against classical methods that must never err
A classical method that must be certain needs queries in the worst case, and against it one query is an exponential gain. The random method errs with probability , independent of : 21 queries make that less than . So “exponentially faster” holds only against error-free classical methods.
Why not the others
- B. One run settles it with certainty: has probability 1 for a constant and 0 for a balanced one. The advantage is real; it is exponential only against methods that must never err.
- C. A query reveals one value , not one bit of anything, and a balanced can agree on inputs. So a method that must be certain can need queries. The headline fails for another reason: it forgets methods allowed a tiny error.
- D. That count is for a method that must be certain. The random method errs with probability whatever is, so 21 queries bring the error below one in a million even for . Against that, one quantum query is a modest gain. The headline is tempting because the certain count really does grow exponentially.
12 / 15 · Practice
Practice
Three items, each with new numbers when it comes back. Hints are there if you need them.
Check yourself
What is the amplitude of in ?
Hints
- What sign does give for and ?
- Every amplitude of has size ; its sign is minus when and share an odd number of 1s.
- They have no 1 in the same place, so . The size is .
Show the answer
Answer:
and have no 1 in the same place, so and the sign is . The size is , so the amplitude is .
Line up and and multiply bit by bit: , , , . The products add to 0, so and the sign is . Every amplitude of has size , so the amplitude of is .
Common slips
- : Right size, wrong sign. The sign is : and have no 1 in the same place, so and the sign is plus.
- : is the size of a probability here. Each amplitude has size , so that the 16 squared magnitudes add up to 1.
Check yourself
Deutsch–Jozsa with . The balanced function is 1 on the inputs , , , and 0 on the other four. What is the amplitude of in the data register just before the measurement?
Hints
- Which two signs does each input contribute to the amplitude of ?
- The amplitude is the average of the eight signs : one from the last Hadamards, one from the chip.
- List for : 0, 1, 1, 0, 1, 0, 0, 1. A term is where this differs from .
Show the answer
Answer:
The eight signs are +, -, +, +, +, +, -, +; they add up to , so the amplitude is .
Go through . The values are 0, 1, 1, 0, 1, 0, 0, 1; the values are 0, 0, 1, 0, 1, 0, 1, 1. Each term is where they agree and where they differ: +, -, +, +, +, +, -, +. The sum is , so the amplitude is , and has probability .
Common slips
- : The chips alone, , average to 0 for a balanced : that is the amplitude. For every term also carries the sign from the last Hadamards.
- : That is the probability, the squared amplitude. The amplitude itself is .
- : Right size, wrong sign. Recount the signs : a term is exactly when and differ.
Check yourself
A balanced on 2-bit inputs (four of them). You query two different inputs, chosen at random. What is the probability that the two values agree, so that the random method wrongly says “constant”?
Hints
- After the first answer, how many of the remaining inputs give the same value?
- Each value belongs to 2 inputs, and one of them has been used. 3 inputs remain.
- So the chance is 1 out of 3.
Show the answer
Answer:
Whatever the first value, 1 of the 3 remaining inputs shares it, so the probability is . In general it is : already better than independent queries, which give .
A balanced on 4 inputs has 2 inputs with each value. The first query gives some value; 1 other input has that value, and the second query picks one of the 3 remaining inputs at random. So the chance that the two agree is . With independent queries (repeats allowed) it would be .
Common slips
- : That is the answer when the second query may repeat the first input: . Here the inputs are different, and one input of the first value is already used up.
- : The numerator is right: 1 unused input shares the first value. But the second query chooses among the 3 inputs that are left, not all 4.
13 / 15 · Explain
Explain it
Explain it
One measurement can’t read both and . How, then, does a single use of in Deutsch’s algorithm decide whether is constant or balanced?
Show a model answer
With the target in , leaves the target alone and multiplies each branch of the data qubit by : phase kickback. So after the query the data qubit is if and if not. The last makes the two branches interfere: matching signs add up on , opposite signs on . A 0/1-basis measurement then gives with certainty. You learn only that one global bit, never or themselves.
A good answer covers
- Kickback: with the target in , puts the sign on each branch of the data qubit
- The last makes the branches interfere: equal signs give , opposite signs give , with certainty
- Only the global bit is learned, not or
- The target stays ; the answer ends up in the data qubit
14 / 15 · Mastery check
Mastery check
Check yourself
A quantum computer applies once to a superposition of all four 2-bit inputs, producing . Then every qubit is measured in the 0/1 basis. What does this one run tell you about ?
- AThe value at one input , chosen at random
- BNothing: measuring a superposition gives meaningless random bits
- COnly , because the inputs started in
- DAll four values : the whole table of
Show the answer
Answer: A. The value at one input , chosen at random
Each branch has amplitude . The measurement picks one branch at random, with probability each, and returns its input and its value: one per run, which is no more than one classical query gives.
Why not the others
- B. The bits are not meaningless. Every branch is , so in every result the last bit equals of the first ones: you learn one genuine value.
- C. Every input has the same amplitude, , so the measured is random: turns up only one time in 4.
- D. The state involves all four values, but a 0/1 measurement of 3 qubits returns 3 bits: one input and its value . The other branches are gone once you have measured.
Check yourself
A student builds Deutsch’s circuit but prepares the bottom qubit in instead of , so it enters as . Everything else is the same. What does the 0/1-basis measurement of the top qubit give?
- A0 or 1 at random, with probability each
- B0 for every , so the circuit no longer tells constant from balanced
- C, as before: the target doesn’t matter
- DNothing on top; the answer now appears on the bottom qubit
Show the answer
Answer: B. 0 for every , so the circuit no longer tells constant from balanced
: no sign, for any . The state stays , the last gives , and the top qubit reads 0 whatever is. The target is what turns into a sign.
Why not the others
- A. With no signs kicked back, the data qubit is still after , and exactly. Two Hadamards in a row undo each other; nothing here randomizes the top qubit.
- C. The target matters. Kickback needs the flip to change the target’s sign, and . With no branch picks up a sign, so the top qubit returns to for every .
- D. The bottom qubit is before and after , since for every . Measured in the 0/1 basis it gives a random bit that says nothing about .
Check yourself
What is the amplitude of in ?
Hints
- What sign does give for and ?
- Every amplitude of has size ; its sign is minus when and share an odd number of 1s.
- They share a 1 in 2 places, so . The size is .
Show the answer
Answer:
and share a 1 in 2 places, so and the sign is . The size is , so the amplitude is .
Line up and and multiply bit by bit: , , . The products add to 2, so and the sign is . Every amplitude of has size , so the amplitude of is .
Common slips
- : Right size, wrong sign. The sign is : and share a 1 in 2 places, so and the sign is plus.
- : is the size of a probability here. Each amplitude has size , so that the 8 squared magnitudes add up to 1.
Check yourself
Deutsch–Jozsa with and , , , . What does the 0/1-basis measurement of the two data qubits give?
- A with certainty
- B with certainty
- C with certainty
- D with certainty
- EEach of the four strings with probability
Show the answer
Answer: C. with certainty
For the four signs are +, +, +, +: they all agree, so has amplitude and every other string has amplitude 0. (Here .)
Why not the others
- A. All zeros would mean constant, but this is balanced: two 0s and two 1s, so the four chips +, +, -, - cancel on .
- B. For the four signs are +, -, -, +: they cancel, so this outcome never occurs.
- D. For the four signs are +, -, +, -: they cancel, so this outcome never occurs.
- E. The Hadamards don’t just spread amplitude around. For each outcome the last adds four signed contributions, and here they add up fully on one string and cancel on the other three.
Check yourself
A black box computes on 4-bit strings (sixteen inputs). You are promised that is either constant or balanced (0 on exactly 8 inputs and 1 on the other 8). Querying one input at a time, and needing to be certain, how many queries might you need in the worst case?
- A
- B
- C
- D
Show the answer
Answer: C.
In the worst case the first 8 answers agree, which a balanced allows. Query number 9 decides: for .
Why not the others
- A. Two queries settle it only if they disagree. If they agree, a balanced is still possible: 8 inputs share each value.
- B. The count depends on the number of inputs, not on the number of bits in . A balanced can give the same value on any 8 inputs, so 8 agreeing answers prove nothing.
- D. You never need all 16. A balanced has only 8 inputs of each value, so once 9 answers agree, must be constant.
15 / 15 · Recap
Recap
From memory
Before reading the summary, write down what you remember. Pulling it back from memory is what makes it last.
What does one run of on a superposition, followed by a 0/1 measurement, tell you? Why is that no speedup?
Show the key points
- One pair , with random
- Measuring the same register again repeats it; a new pair needs a fresh copy and another use of
- An advantage needs interference that answers a global question about
Write the four states of Deutsch’s algorithm, to .
Show the key points
- , then
- Kickback: ; the target stays
- ; measure the top qubit
Why does all zeros mean constant in Deutsch–Jozsa, and how well can a randomized classical method do?
Show the key points
- The amplitude is the average of the chips, : if constant, 0 if balanced
- A deterministic method can need queries
- random queries err with probability at most , whatever is
Key ideas
is reversible. On it gives , but a measurement returns one random pair.
Phase kickback: . The target is unchanged; becomes a sign on the data branch.
Deutsch: , so one query reveals whether , and nothing more.
. In Deutsch–Jozsa the amplitude is the average of the chips: if is constant, 0 if balanced.
One quantum query against for a certain classical answer, but only a few for a nearly certain one: random queries err with probability at most .
Go further
Free resources for when you want more than this lesson covers.
- Fundamentals of quantum algorithms: Quantum query algorithmsJohn Watrous, IBM Quantum · Course
Goes past Deutsch–Jozsa to the Bernstein–Vazirani problem and Simon’s algorithm, a stepping stone to Shor’s.
- Quantum computing for computer scientistsMicrosoft Research · Video
A recorded talk that rebuilds bits, qubits and gates as matrices and ends by running the Deutsch problem in Q# code.
- Deutsch–Jozsa algorithmWikipedia · Article
The history: Deutsch’s 1985 version worked only half the time, and the one-query version that is always right came in 1998.
Math refreshers
The toolkit topics this lesson leans on.
- Bits, XOR and bit stringsx ⊕ y, x · z mod 2, sums over {0,1}ⁿ, and signs that depend on f(x)