Bernstein-Vazirani algorithm
An oracle algorithm that recovers a hidden binary string encoded in a linear Boolean function using one coherent query.
Also called BV algorithm
On this page
Definition and significance
Suppose f_s(x)=s dot x modulo two, where the unknown n-bit string s specifies a linear function. Bernstein-Vazirani recovers s with one coherent oracle query, whereas a classical deterministic query model needs n independent evaluations. The advantage is linear in query count for this particular task; it is not a general exponential speedup.
The algorithm provides an unusually clear example of how a phase pattern across basis states becomes a specific output string. Its standard implementation can be explained entirely through products of single-qubit states and a phase oracle; large entanglement is not necessary for this separation.
Mechanism and mathematical treatment
After phase kickback, the input state is 2^(-n/2) sum_x (-1)^(s dot x)|x>. Since (-1)^(s dot x) factors into product_j (-1)^(s_j x_j), this state equals the tensor product over j of (|0>+(-1)^(s_j)|1>)/sqrt(2). Applying H to each factor produces |s_j>, so the final register is exactly |s>.
An added constant b in f(x)=s dot x XOR b contributes (-1)^b to every amplitude. That factor is global and therefore does not affect recovery of s. The same phase-query experiment does not reveal b.
Fully worked reference example
Choose s=101 in left-to-right x0,x1,x2 order. The predicate is x0 XOR x2. After kickback, the input factors as |->|+>|->. The final Hadamards give |1>|0>|1>. A classical procedure can recover the same string by querying the three unit vectors: f(100)=1, f(010)=0 and f(001)=1.
For the affine function x0 XOR x2 XOR 1, the quantum state gains an overall minus sign but the measured answer remains 101. A separate classical query at x=000 would reveal the constant term. The distinction illustrates why global phase cannot encode an independently readable bit in this experiment.
Limitations and common misconceptions
The oracle's construction may already expose s if it is supplied as a known gate list. Query complexity treats the oracle as a callable black box. A visible demonstration circuit is useful for explaining the mathematics, but it does not make the hidden-string task difficult for an observer who can inspect that circuit.
Scientific relationships
A hidden linear coefficient and a hidden XOR period are different oracle promises.
A Boolean linear function becomes a factored phase pattern.
Historical source context
The associated complexity work appeared in preliminary conference form in 1993 and as a substantially developed SIAM journal article in October 1997. Conference and journal dates should remain distinct in historical records.
Recovering coefficients with nonstandard classical queries
For an unknown four-bit string s, a classical query at x returns the binary inner product x dot s. The usual unit-vector queries form the identity matrix, but any full-rank binary query matrix works. Choose rows 1100, 0110, 0011 and 0001. For s=1101, the returned values are 0,1,1,1. Solve from the last equation upward: s3=1; s2 XOR s3=1 gives s2=0; s1 XOR s2=1 gives s1=1; and s0 XOR s1=0 gives s0=1.
This example shows that the classical lower bound is an information statement, not a requirement to use a particular query schedule. Each noiseless Boolean answer contributes at most one binary equation. Fewer than n independent equations leave multiple coefficient strings consistent with the observations. Adaptivity does not change that worst-case counting argument for exact identification of an arbitrary n-bit string.
The quantum phase-query procedure transforms the entire linear character into its label in one coherent query. Its n measured output bits are not n independent oracle answers read from amplitudes; they are the result of a specific interference calculation whose promise restricts the possible functions to 2^n linear characters. The restricted input family is central to the result.
One corrupted truth-table value
Suppose the phase oracle differs from the promised linear function at exactly one input x*. Let N=2^n. Write its phase pattern as the ideal character, except that one sign is reversed. The final amplitude at y equals delta_(y,s) minus (2/N)(-1)^[x* dot (s XOR y)]. At y=s, the amplitude is 1-2/N. At every other y, its magnitude is 2/N. Therefore the correct string is observed with probability (1-2/N)^2, while each incorrect string has probability 4/N^2.
For n=4, the correct probability is (7/8)^2=49/64. Each of the fifteen incorrect strings has probability 1/64, and the total is 49/64+15/64=1. The position x* affects the signs of incorrect amplitudes but not their computational probabilities. One sample therefore cannot identify which truth-table entry was corrupted, even though the complete output state contains that phase information.
This calculation describes a fixed coherent oracle defect in one basis input. It is not the same noise model as independently flipping a measured output bit, nor is it a generic hardware error rate. Specifying the defect at the phase-function level makes the prediction exact. If multiple truth-table values are changed, their error amplitudes can interfere constructively or destructively, so simply multiplying the one-defect failure probability is unjustified.
Local phase miscalibration and an exact product distribution
A different imperfect oracle applies a factor exp[i(pi s_j+delta_j)x_j] on each input bit. After the final Hadamard on bit j, the probability of the intended output s_j is cos^2(delta_j/2), and the probability of its complement is sin^2(delta_j/2). Because the phase pattern still factorizes, the complete output distribution is the product of these single-bit distributions. The chance of recovering the full string is product_j cos^2(delta_j/2).
If all four offsets are pi/6, each bit is correct with probability (2+sqrt(3))/4, approximately 0.933013. The complete string is correct with probability approximately 0.757792. The error is coherent in each preparation, but the final computational samples have an independent-bit form for this particular factorized model. Entangling phase errors would generally break that factorization.
For small offsets, cos^2(delta_j/2)=1-delta_j^2/4+O(delta_j^4), so the leading full-string failure probability is approximately one-quarter the sum of squared offsets. This expansion is useful only when the accumulated correction is small. A large number of small offsets can still reduce the full-string success substantially. Reporting only the per-bit accuracy would hide that scaling.
If the function is affine, f(x)=s dot x XOR b, the phase experiment remains insensitive to b. Recovering both s and b requires an extra interface use that reveals the offset, such as evaluating the value oracle at zero. A visible compiled oracle can expose both coefficients directly in its gate description, so the mathematical query advantage pertains to the specified black-box task. For these small synthetic instances, classical binary elimination and direct Fourier summation provide complete verification.
Sources
Verification scope
Recorded source check ·
Formal or reference-semantic source anchor only; no SDK execution, hardware run, or empirical advantage is asserted. Original worked examples are independent mathematical constructions.