Detailed Solutions: Week 3 Assignment
1. Quantum speedup
(a) Deutsch–Jozsa (DJ). Quantum needs a single oracle query to distinguish constant vs.
balanced functions, whereas any deterministic classical algorithm requires 2n−1 + 1 queries in
the worst case (see Q4). This is an exponential reduction in query complexity.
(b) Bernstein–Vazirani (BV). Quantum uses exactly 1 query; the best classical deter-
ministic method uses n queries. This is a linear (not exponential) improvement.
(c) Integer factorization. Shor’s algorithm runs in polynomial time in log N , while
the best known classical algorithms are sub-exponential but super-polynomial in log N . This
is commonly reported as a super-polynomial (often described as “exponential”) speedup in
n = log N . √
(d) Unstructured search. Grover gives a quadratic speedup O( N ) vs. classical O(N ),
not exponential.
Correct options: (a), (c).
2. 3-qubit Grover: initial angle θ0
3 qubits, N = 2n = 8 basis states and one marked state |101⟩. The equal superposition
With n = P
|s⟩ = √1N x |x⟩ decomposes into “solution/non-solution” as
E
|s⟩ = sin θ0 |w⟩ + cos θ0 w⊥ , where, |w⟩ = |101⟩ is the solution state.
Now, we have,
1 1
sin θ0 = ⟨w|s⟩ = √ = √ .
N 2 2
Hence
1
θ0 = sin−1 √ .
2 2
Correct option: (c)
3. 3-qubit Grover: success probability after two iterations
After k Grover iterations, the success probability is
1
pk = sin2 (2k + 1)θ0 , θ0 = sin−1
√ .
2 2
For k = 2, 1
p2 = sin2 (5θ0 ) = sin2 5 sin−1 √ ≈ 0.97.
2 2
Correct option: (d)
1
4. Classical queries to decide constant vs. balanced (DJ)
Classically (deterministic), to be certain a function is constant, you must see both a 0-output
and a 1-output not occur after enough queries. In the worst case, an adversarial constant
function can make the first 2n−1 inputs all return the same value; only at the next query can
you be sure. Therefore,
2n−1 + 1 queries
are necessary and sufficient in the worst case.
Correct: (d).
5. BV: number of queries to learn a
The BV oracle computes fa (x) = (a · x) mod 2. With phase kickback (prepare the ancilla in |−⟩
and the n inputs in |+⟩⊗n ), a single query imprints the phase (−1)a·x , and Hadamards recover
a exactly in one shot.
Correct: (a).
6. Circuit equalities with Pauli Y
CNOT gate in outer-product notation : P0 ⊗ I + P1 ⊗ X, where P0 = |0⟩⟨0| and P1 = |1⟩⟨1|, and
X is the Pauli-X .
Therefore the circuit
• Y •
can be written in the outer product notation as : (P0 ⊗ I + P1 ⊗ X)(Y ⊗ I)(P0 ⊗ I + P1 ⊗ X)
Performing the multiplication we get : P0 Y P0 ⊗ I + P0 Y P1 ⊗ X + P1 Y P0 ⊗ X + P1 Y P1 ⊗ I
Note that : P0 Y P0 = |0⟩⟨0| (−i|0⟩⟨1| + i|1⟩⟨0|) |0⟩⟨0| = 0
Similarly : P1 Y P1 = |1⟩⟨1| (−i|0⟩⟨1| + i|1⟩⟨0|) |1⟩⟨1| = 0
And , P0 Y P1 = |0⟩⟨0| (−i|0⟩⟨1| + i|1⟩⟨0|) |1⟩⟨1| = −i|0⟩⟨1|
Also P1 Y P0 = |1⟩⟨1| (−i|0⟩⟨1| + i|1⟩⟨0|) |0⟩⟨0| = i|1⟩⟨0|
Therefore, (P0 ⊗ I + P1 ⊗ X)(Y ⊗ I)(P0 ⊗ I + P1 ⊗ X) = (P0 Y P1 + P1 Y P0 ) ⊗ X = Y ⊗ X
Circuit for Y ⊗ X is :
Y
X
Similarly in the outer product notation the circuit
• •
Y
can be written as : (P0 ⊗ I + P1 ⊗ X)(I ⊗ Y )(P0 ⊗ I + P1 ⊗ X)
Performing the multiplication we get : P0 ⊗ Y + P0 P1 ⊗ XY + P1 P0 ⊗ Y X + P1 ⊗ (XY X)
Note that: P1 P0 = |0⟩⟨0|1⟩⟨1| = 0, and XY X = −Y
Therefore, P0 ⊗ Y + P0 P1 ⊗ XY + P1 P0 ⊗ Y X + P1 ⊗ (XY X) = (P0 − P1 ) ⊗ Y = Z ⊗ Y
The circuit for Z ⊗ Y is :
Z
Y
Correct: (b), (c)
2
7. DJ: measurement pattern indicating “balanced”
DJ computes Uf |x⟩ |−⟩ = |x⟩ (−1)f (x) |−⟩. Starting from |+⟩⊗n |−⟩ and ending with H ⊗n on
the first n qubits, the amplitude of |0⟩⊗n is
1 X
(−1)f (x) .
2n
x∈{0,1}n
• If f is constant, this sum equals ±1, so the final state is |0⟩⊗n with certainty.
• If f is balanced, exactly half the terms are +1 and half −1, so the amplitude of |0⟩⊗n is
0, and some other bitstring is observed.
Thus: balanced ⇐⇒ the measurement outcome is any string other than |0⟩⊗n .
Correct: (b).
8. DJ: best-case number of oracle calls
As above, the DJ algorithm needs only one call to Uf to decide constant vs. balanced with
certainty.
Correct: (d).
9. How many Grover iterations?
j √ k
π
For N = 2n with one marked item, the optimal number of Grover iterations is 4 N , which
√
is O( N ).
Correct: (d).
10. BV oracle circuit: identify a
In the standard BV oracle Uf : |x⟩ |y⟩ 7→ |x⟩ |y ⊕ (a · x)⟩, the implementation uses CNOTs from
input qubit i to the ancilla iff ai = 1. Reading the given diagram (controls on the 1st and 3rd
input qubits only), we get
a = a1 a2 a3 a4 = 1 0 1 0,
Correct: (a) .