Bernstein–Vazirani Algorithm
Track: Quantum Algorithms · Difficulty: Intermediate · Est: 14 min
Bernstein–Vazirani Algorithm
Overview
Bernstein–Vazirani (BV) is a “hidden string” algorithm.
You are given oracle access to a function
where:
- is your query,
- is a fixed hidden bitstring,
- means the bitwise dot product mod 2 (XOR of the ANDs).
Goal: recover .
Why it’s interesting:
- Classically, you typically need queries to learn all bits of .
- Quantumly, BV finds with one oracle query, using phase kickback and interference.
Intuition
In the oracle model, the function output is one bit. So it seems like you only learn one bit per query.
BV bypasses that “one-bit bottleneck” by using phase kickback:
- the oracle imprints a structured phase pattern across a superposition of all .
- a final layer of Hadamards converts that phase pattern into the computational basis state .
So the algorithm extracts the entire hidden string in a single query because the oracle’s phase pattern is globally structured.
Algorithm Structure
High-level steps:
- Prepare input qubits in and a target qubit in .
- Apply H to all qubits to create a uniform superposition on the input and on the target.
- Query the oracle once.
- Apply H to the input register.
- Measure the input register; the result is .
Formal Description
Oracle
Use the standard reversible oracle:
As in Deutsch–Jozsa, preparing the target as turns the XOR into a phase:
So after the oracle, the input register is
Why the final Hadamards reveal
Hadamards transform phase patterns into basis states. In BV, the particular phase pattern is exactly the one that maps to after .
Conceptual takeaway:
- the hidden string is not stored in probabilities yet;
- it is stored in the phase relationship across all ;
- the final mixing step turns that phase into a sharp measurement outcome.
Worked Example
Let and hidden string . So
After the oracle (with phase kickback), each basis state gets a sign of :
- if , the sign is +1
- if , the sign is −1
This sign pattern is globally consistent with the hidden string. After applying , the input register collapses to the basis state . Measuring yields 101 with certainty in the ideal model.
Turtle Tip
BV is “phase kickback + one final interference step.” The oracle writes into phase; Hadamards read it out as a basis state.
Common Pitfalls
- Don’t interpret BV as violating information limits. The oracle is a structured black box, and the algorithm exploits that structure.
- Don’t confuse with ordinary real-number dot product. Here it’s mod 2: XOR of bitwise ANDs.
Quick Check
- What is the problem BV solves in one sentence?
- Where is the hidden string stored right after the oracle call: in probabilities or in phase?
What’s Next
BV shows how phase can encode a hidden linear structure. Next we study Simon’s algorithm, which is an early example of period-finding: the oracle hides a secret XOR-period , and measurement reveals constraints that let you reconstruct it.
