Skip to content
Tech Interview Prep
Technical interview guide

Quantum Algorithms I: Deutsch-Jozsa & Grover's Search

The foundational oracle-based algorithms that first demonstrated provable quantum speedups: exponential for Deutsch-Jozsa, quadratic for Grover's search.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v3
Editorial status
Reviewed

Scope: IBM Quantum learning and Qiskit current algorithm documentation; original Deutsch-Jozsa, Grover, BBHT, and query lower-bound literature reviewed 2026-09-04.

Overview

Curated: · Written: · Reviewed:

Quantum Algorithms I: Deutsch-Jozsa & Grover's Search

In one line

Both are black-box oracle algorithms that count coherent oracle calls. Deutsch-Jozsa decides constant versus balanced in one query, but only under that promise. Grover finds a marked item in about pi/4 times sqrt(N/M) queries, a quadratic saving over unstructured search. Reach for them when the question concerns query complexity, not end-to-end runtime.

Key definitions

  • Phase oracle: a reversible unitary that maps |x> to (-1)^f(x)|x>, with f(x)=1 marking an item.
  • Phase kickback: preparing the output qubit in |-> makes |x>|-> go to (-1)^f(x)|x>|->, so the function value lands in the sign.
  • Promise: the input precondition that f is constant or balanced. The circuit does not check it.
  • Grover iterate: phase oracle followed by diffusion D = 2|s><s| - I.
  • Marked set M: the items the oracle flags, out of N candidates.
  • Amplitude amplification: Grover generalized to any state preparation A and its inverse.

Formulas and complexity

P(000)=∣12n∑x(−1)f(x)∣2P(000) = \left|\frac{1}{2^n}\sum_{x}(-1)^{f(x)}\right|^2 θ=2arcsin⁡M/N,Pk=sin⁡2 ⁣((2k+1)θ2)\theta = 2\arcsin\sqrt{M/N}, \qquad P_k = \sin^2\!\left(\frac{(2k+1)\theta}{2}\right) kopt≈π4N/M,π4220≈804k_{\text{opt}} \approx \frac{\pi}{4}\sqrt{N/M}, \qquad \frac{\pi}{4}\sqrt{2^{20}} \approx 804 Deutsch-Jozsa: 1 exact query (quantum) versus 2n−1+1 deterministic classical worst case\text{Deutsch-Jozsa: 1 exact query (quantum) versus } 2^{n-1}+1 \text{ deterministic classical worst case}

For n=20 the classical worst case is 524,289 queries.

How it works

Deutsch-Jozsa prepares a uniform superposition, kicks the function values into signs, applies Hadamards, and reads all-zeros as constant. Grover repeats the iterate, and each pass rotates the state inside the good/bad two-dimensional subspace.

repeat k times Hadamards: uniform superposition Phase oracle flips marked items Diffusion: reflect about the mean Measure, then check candidate classically

When to use and when not to

SituationUseAvoid
Constant vs balanced, promise holdsDeutsch-Jozsa, one queryPromise unverified or violated
Unstructured search, M knownGrover with pi/4 sqrt(N/M) iterationsFixed M=1 schedule when M is larger
M unknownQuantum counting or randomized scheduleGuessing the iteration count
Data must be loaded into the oracleOnly when loading cost is includedIgnoring data-loading and arithmetic cost
Deep circuits on today's hardwareNot a NISQ workloadClaiming runtime from iteration count

Traps interviewers probe

  1. Counting queries as runtime. Fix: cost the oracle and diffuser in two-qubit gates. Grover at N=2^20 is about 350,000 two-qubit gates, and at 0.5% error per gate the fault-free probability is roughly e^-1750.
  2. Running Deutsch-Jozsa on an unpromised function. Fix: check balance before trusting the output. For f=1 on 2 of 8 inputs, P(000) = 0.25, and the caller would read a wrong verdict with no error signal.
  3. Using the M=1 schedule for an instance with more solutions. Fix: use pi/4 sqrt(N/M) or count first. For N=1024 with 50 iterations, the marked item appears in about 0.02% of shots, because the run overshot the optimum near 25.
  4. Skipping uncomputation. Fix: run the oracle alone on a small instance and assert every ancilla returns to |0> with probability one. A flat histogram is not hardware noise, and more shots will not fix it.
  5. Treating an unmarked result as proof of no solution. Fix: verify the candidate against the predicate with one classical evaluation. A zero-solution oracle returns a random candidate that looks valid.

Interview tips

Opening: "Both are query algorithms. Deutsch-Jozsa separates constant from balanced exactly in one query, where deterministic classical needs 2^(n-1)+1. Grover needs about pi/4 sqrt(N/M) queries, a quadratic saving, and I would cost the oracle before claiming any runtime benefit."

Follow-ups to expect:

  • What happens if the promise is violated? A confident wrong answer, because the all-zeros probability is no longer 0 or 1.
  • What if M is unknown? Quantum counting first, or the exponentially increasing randomized schedule, which finds a solution in expected order sqrt(N/M) queries.
  • Why does the output qubit need |->? It converts the bit flip into a sign through phase kickback.
  • Why is the advantage not an application speedup? Loading, arithmetic, ancillas and error correction can dominate.
  • Where does Grover generalize? Amplitude amplification, which raises a success probability p to near one in about 1/sqrt(p) repetitions.

30-second outline: Name the query model. State the promise or the value of M. Give the query count and the classical comparison. Note that the oracle must be reversible and uncomputed. Close with the fault-tolerant cost, and say that every Grover result is verified classically.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.