What makes Bernstein-Vazirani an instructive speedup without making it a universal search engine?
The hidden string appears through a promised oracle
Source research checked . Teaching calculations are ideal models.
The oracle computes the parity of a secret bit string s with an input x. Choose s=1011 and four input bits. The task is to identify s through calls to this specified oracle. It is not a model of opening arbitrary files or searching a database without accounting for how the oracle is built.
The algorithm’s compactness comes from the promise: all responses follow one linear parity rule. Removing that structure changes the problem. The reader should see the cancellation explicitly rather than accept “quantum parallelism” as a complete explanation. A four-bit case is small enough to enumerate every input and verify every sign.
Figure and table scope: Display all sixteen four-bit outputs for the fixed parity mask s=1011 and the ideal Bernstein–Vazirani oracle.
Derivation step 1: Prepare the input register in an equal superposition of every x and an auxiliary target in minus. The oracle’s output flip becomes a phase (-1)^(s·x).
Derivation step 2: Apply a Hadamard to every input qubit. The amplitude of a candidate output y is the average of (-1)^((s⊕y)·x) over all x.
Derivation step 3: When y=s, every term equals one. When y differs from s in at least one position, terms pair off with opposite signs and sum to zero.
Derivation step 4: The ideal output is therefore 1011 in the stated register order. Oracle construction and control accuracy are outside this query-count derivation.
Separate challenge: For candidate y=1001 and secret s=1011, identify a bit position that makes the phase sum cancel.
Worked challenge answer: The strings differ in the third position when written left to right. Pair each x with the x obtained by flipping that position. Their exponents differ by one, so their contributions have opposite signs. All sixteen terms cancel in eight pairs.
Start with the assumptions
- Exact parity promise, coherent oracle access, no noise and a declared bit order. The count is oracle queries, not a complete end-to-end runtime benchmark.
P(y=s)=1; P(y≠s)=0 under the exact parity promise.

Compare the input regimes
Each case uses invented inputs. The results follow from this model and do not describe measured hardware.
Reference example with separately scoped figure
Complete inputs
- reference scenario
- Let s=1011 and f(x)=s dot x modulo two. Compute the ideal final state after Hadamards, a phase oracle and Hadamards.
- separate figure scope
- Display all sixteen four-bit outputs for the fixed parity mask s=1011 and the ideal Bernstein–Vazirani oracle.
- Amplitude of output y = 2^(-n) sum_x (-1)^[(s xor y) dot x]. This equals 1 for y=s and 0 otherwise.
| Reference | Prediction |
|---|---|
| Original declared example | For four input qubits the output is 1011 with certainty in the ideal promised setting. Classical single-position queries return the four mask bits separately. |
| Decoded integer (four-bit output) | Ideal output |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 3 | 0 |
| 5 | 0 |
| 7 | 0 |
| 9 | 0 |
| 11 | 1 |
| 13 | 0 |
| 15 | 0 |
The declared reference example predicts: For four input qubits the output is 1011 with certainty in the ideal promised setting. Classical single-position queries return the four mask bits separately.
Try the reasoning: For candidate y=1001 and secret s=1011, identify a bit position that makes the phase sum cancel.
Sources and model boundaries
- IBM Quantum Learning: Deutsch-Jozsa and Bernstein-Vazirani ↗
Primary scientific context for an original ideal teaching example. Source research checked 19 October 2026; site integration inspected 20 October 2026. These are different checks.