smartyfy.mrindigi.com

Quantum Computing Master Course — 064. Bernstein Vazirani Algorithm

Lesson 064: Bernstein Vazirani Algorithm

Smartyfy Quantum Computing Master Course

Prerequisites and objectives

The Bernstein-Vazirani problem asks for an unknown binary string hidden in a linear Boolean function. A single coherent query, followed by interference, recovers the entire string in the ideal model. You will derive the result from a binary character sum, work through a concrete hidden string, and identify the access assumptions behind the comparison.

Let s be an unknown n-bit string. The promise is f(x)=s·x, where the dot product means XOR of the coordinatewise bit products. The algorithm receives oracle access to f and must return s. It does not receive the circuit construction code that may have been used to encode s.

Binary dot products are parity calculations

For s=s(n−1)…s0 and x=x(n−1)…x0, calculate s·x as s(n−1)x(n−1)⊕…⊕s0x0. The result is one bit, even though both strings contain n bits.

Take s=1011 and x=1101 in left-to-right order. Coordinate products are 1,0,0,1. Their XOR is zero because two contributions are one. This differs from an ordinary integer dot product, which would equal two before reducing modulo two.

The basis string ei with a single one at position i satisfies s·ei=si. A classical exact strategy can therefore query each basis string and recover all n hidden bits using n queries.

Use the same interference circuit

Prepare the input register uniformly with n Hadamards and prepare a separate target in |−⟩. One function-oracle query applies phase (−1) raised to s·x to input branch x. Apply H to every input qubit again and measure that register.

The amplitude of output z is Az=(1/2ⁿ)Σx(−1) raised to (s·x)⊕(x·z). Binary distributivity combines the exponent into x·(s⊕z).

If z=s, the exponent vanishes for every x, so all 2ⁿ terms equal one and Az=1. If z differs from s, choose a position where s⊕z has a one. Pair every x with the string obtained by flipping that position. The two terms have opposite signs and cancel.

Thus Az is one exactly at z=s and zero elsewhere. The final input state is |s⟩, and the target remains |−⟩. This is an exact ideal result, not an estimate assembled from many independent samples.

A factorized view of the same proof

The phase (−1) raised to s·x equals the product of (−1) raised to sixi over all positions i. Consequently the phase-marked uniform input factors into single-qubit states: |+⟩ at positions where si=0 and |−⟩ where si=1.

The last Hadamard layer maps each factor to its corresponding basis bit. This viewpoint is especially transparent for the linear promise. It also shows that this particular computation need not create entanglement among the input qubits in the standard ideal construction.

Absence of that entanglement does not invalidate the coherent-query advantage. It reminds us to analyze the actual resource and interface rather than treating entanglement as an automatic explanation of every quantum algorithm.

Four input wires in most-significant-first order start after the phase query in minus, plus, minus, minus states. Their final Hadamards produce bits 1, 0, 1, 1. A character-sum note distinguishes sixteen equal signs at z=s from cancelling sign pairs elsewhere. The separate oracle target remains minus.
The linear promise factorizes the phase pattern. The final local Hadamards translate its signs into the requested bit string. Open full-size diagram

Worked hidden string 1011

For s=1011, the phase-marked data register is |−⟩|+⟩|−⟩|−⟩ in the stated most-significant-first order. Applying H to each factor produces |1011⟩ with probability one.

Classical basis queries for the hidden string 1011
Input x Oracle answer f(x) Hidden bit identified
1000 1 Leftmost bit
0100 0 Second bit
0010 1 Third bit
0001 1 Rightmost bit

A toy oracle can be built with a CNOT from each input position having si=1 into the target. This example uses three CNOTs. The oracle builder knows s; the black-box solver is assumed not to inspect those control choices directly.

If the explicit gate list revealing s is part of the ordinary input available to both solvers, a classical algorithm can read those labels. That is a different access model from learning s only through function-value queries.

Why n classical exact queries are necessary

Each classical query returns one bit and therefore imposes one binary linear equation on s. After fewer than n queries, the collected equations have rank at most the number of queries. At least two hidden strings remain consistent with some exact-query transcript.

Equivalently, a deterministic binary decision tree of depth k has at most 2^k leaves, while exact identification must distinguish 2ⁿ possible hidden strings. If k<n, there are too few leaves. Adaptive query choices do not evade this counting argument.

The n basis queries attain the bound. The ideal quantum procedure uses one coherent function query and O(n) surrounding gates under a supplied-oracle model. This is a linear-versus-constant query comparison, not a claim of constant total runtime while writing n output bits.

An affine offset changes only a global sign

Suppose the oracle instead has f(x)=s·x⊕b for an unknown constant bit b. Phase kickback contributes an additional common factor (−1) raised to b. The same circuit still returns s, but it does not reveal b.

A separate ordinary function query at x=0…0 reveals b because s·0=0. This extension illustrates what the interference circuit preserves and what it discards: the slope string controls relative signs, while the common offset becomes global.

The original promise has b=0, so no offset recovery is required. Always match the requested output to the exact function family instead of assuming a circuit identifies every parameter in a broader model.

Noise and verification

For a supplied small oracle, verify both its basis truth table and its action on superpositions. Input-dependent phases not included in Uf can change the algorithm even if computational labels are correct. Later lessons build these verification checks explicitly.

On noisy hardware, repeated results may not all equal s. A histogram can evaluate an implementation, but interpreting its confidence requires an error model and adequate tests. The ideal proof does not by itself certify the physical oracle, preparation, or readout.

Four exercises with worked solutions

  1. For s=011 and x=110, compute f(x).

    Solution. Coordinate products are 0,1,0, whose XOR is one. The answer is a parity bit, not the integer value of either string.

  2. What output does the quantum circuit produce for s=000?

    Solution. No relative phases are introduced. The final Hadamards return the input register to |000⟩, correctly identifying the all-zero hidden string.

  3. Why does the amplitude at z≠s vanish?

    Solution. A position where z and s differ pairs each x with a bit-flipped partner. The pair contributes equal-magnitude opposite signs to the character sum, so the total cancels.

  4. For f(x)=101·x⊕1, what does the same circuit reveal, and how could the remaining bit be found?

    Solution. It reveals 101. The extra one only supplies a global minus sign. Querying the function at 000 returns the offset one.

Five explained multiple-choice questions

  1. The promised function is: A. A modular integer sum. B. A function with exactly one marked input. C. An arbitrary truth table. D. A binary linear dot product with hidden s.

    Answer: D. The linear structure creates the character sum that isolates s.

  2. The ideal final input state is: A. |s⟩. B. A classical list of every f(x). C. Uniform over all strings. D. Always |0…0⟩.

    Answer: A. All other amplitudes cancel after the final Hadamards.

  3. The standard exact classical query count is: A. One for arbitrary n. B. 2ⁿ always. C. n in the worst case. D. Zero if the oracle is opaque.

    Answer: C. Each answer supplies one binary constraint, and basis queries attain n.

  4. An unknown affine offset b appears here as: A. A normalization error. B. A global phase that this measurement does not reveal. C. A second output register automatically. D. A changed hidden string.

    Answer: B. Multiplying every phase by the same sign leaves the measured s unchanged.

  5. Inspecting an oracle gate list that directly reveals s: A. Proves a lower bound. B. Preserves the same opaque-access comparison. C. Changes the information-access model. D. Is required by the quantum proof.

    Answer: C. The hidden parameter is no longer available only through queries.

Pitfalls and summary

Use the binary dot product, preserve bit order, and state whether the oracle is opaque. One coherent query identifies the hidden linear string, while total gate work and output size still scale with n. A common affine offset is a separate piece of information.

Primary sources and further study

These sources support the definitions and context. The numerical examples, exercises, and explanations here were prepared for this lesson. Research papers are optional advanced reading.