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
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.
When to use and when not to
| Situation | Use | Avoid |
|---|---|---|
| Constant vs balanced, promise holds | Deutsch-Jozsa, one query | Promise unverified or violated |
| Unstructured search, M known | Grover with pi/4 sqrt(N/M) iterations | Fixed M=1 schedule when M is larger |
| M unknown | Quantum counting or randomized schedule | Guessing the iteration count |
| Data must be loaded into the oracle | Only when loading cost is included | Ignoring data-loading and arithmetic cost |
| Deep circuits on today's hardware | Not a NISQ workload | Claiming runtime from iteration count |
Traps interviewers probe
- 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.
- 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.
- 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.
- 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.
- 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.