Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 28

Quantum Advantage in Bernstein-Vazirani

Recommended resources

Hello! In our previous lesson, we moved from the theory of the Deutsch-Jozsa algorithm to its practical implementation in Qiskit. You saw how a "Hadamard sandwich" circuit could distinguish between constant and balanced functions in a single shot.

Today, we'll explore a new problem that, perhaps surprisingly, uses the exact same circuit structure. This lesson introduces the Bernstein-Vazirani algorithm. Our goal is to describe the Bernstein-Vazirani problem and its quantum advantage. We'll see how this algorithm shifts the focus from identifying a function's global property (like in Deutsch-Jozsa) to extracting specific, hidden information from it.


1. From Global Properties to Hidden Information

The Deutsch-Jozsa algorithm was our first example of a quantum speedup, but the problem it solves is somewhat abstract. The Bernstein-Vazirani algorithm provides a more compelling case for the power of quantum computation. It tackles a problem of information extraction: finding a secret bitstring hidden inside a black-box function, or oracle.

First, let's briefly formalize the idea of an oracle-based problem, which is central to many quantum algorithms.

Quantum Query Algorithms | Understanding Quantum Information & Computation | Lesson 05

This Qiskit video introduces the concept of quantum query algorithms and the oracle model.

Watch the first two segments of this video. Focus on the explanation of the query model (here). This clarifies the "black box" idea, where we can send inputs and get outputs but cannot see the internal workings. The cost of an algorithm in this model is measured by how many times we need to "query" the oracle. Then, review how a quantum query is implemented as a unitary gate, U_f (here). This is the same type of oracle we used in the Deutsch-Jozsa algorithm.

With that context, we can now define the specific problem that the Bernstein-Vazirani algorithm solves.

The Bernstein-Vazirani Problem

Imagine you are given access to an oracle that implements a function . This function takes an -bit input string and returns a single bit (0 or 1). You are promised that for some hidden, unknown -bit string , the function is defined as:

Your task is to find the hidden string .

The operation is a bitwise dot product. It works like this:

  1. Perform a bitwise AND between the strings and .
  2. Sum the bits of the resulting string and take the result modulo 2 (which is the same as finding the parity or XORing all the bits together).

For example, if , the hidden string is , and you choose the input :

  • So,

The following article provides a crisp definition of the problem.

The Bernstein–Vazirani Algorithm

This article introduces the Bernstein-Vazirani problem and sets up the classical vs. quantum comparison.

Read the sections "Introduction" and "The Problem". This will reinforce the definition and give you another example of the bitwise dot product.


2. The Classical Solution: One Bit at a Time

Before diving into the quantum approach, let's consider how we would solve this with a classical computer. How many times would we need to query the oracle to guarantee we find ?

To find the -bit string , we need to determine each of its bits. A clever way to do this is to choose our inputs strategically to isolate one bit of at a time.

Consider querying the oracle with an input that is all zeros except for a single '1' at the -th position.

  • To find , we query with . The dot product becomes . So, the oracle's output is exactly the first bit of .
  • To find , we query with . The dot product becomes . The output is the second bit of .
  • ...and so on.

After such queries, we will have determined all bits of . It can be proven that you cannot do better than this classically. To recover bits of information, you need to gain at least one bit of information per query, which requires a minimum of queries.

The video below gives a clear walkthrough of this classical strategy.

Quantum Computing: Bernstein-Vazirani Algorithm

This video clearly explains the optimal classical algorithm for the Bernstein-Vazirani problem.

Watch the section explaining the classical algorithm (here). The example with s=101 makes the process very clear.

So, the classical query complexity is O(n). To find a 100-bit string, you need 100 queries.


3. The Quantum Solution: A Single Query

Now for the quantum approach. As mentioned, the Bernstein-Vazirani algorithm uses the same circuit as the Deutsch-Jozsa algorithm.

Bernstein-Vazirani Circuit Diagram (n=3, s=101)
The quantum circuit for the Bernstein-Vazirani algorithm with n=3 input qubits and a hidden string s=101. Note that this is identical in structure to the Deutsch-Jozsa circuit.

Let's see how this structure solves the problem in a single query. The magic lies in how this specific oracle, implementing , interacts with the superposition created by the Hadamard gates.

Here’s a conceptual walkthrough:

  1. Initialization: We start with input qubits in the state and one ancilla qubit in the state.

  2. Superposition: We apply Hadamard gates to all qubits. The input register becomes an equal superposition of all possible input strings, and the ancilla becomes . The combined state is:

  3. Oracle and Phase Kickback: We apply the oracle . As we saw with Deutsch-Jozsa, when the ancilla is in the state, the oracle's output is "kicked back" as a phase of to the input register. Since , our state becomes:

    At this point, the hidden string is encoded in the relative phases of the superposition. The problem now is how to read it out.

  4. Interference: We apply Hadamard gates to the input qubits again. This is the crucial interference step. It turns out that this specific transformation has a remarkable property:

    The final Hadamard gates cause all the states in the superposition to interfere destructively, except for the one corresponding to our hidden string, .

  5. Measurement: When we measure the input qubits, we get the string with 100% probability.

The Qiskit video below explains precisely how the Deutsch-Jozsa circuit, when given a Bernstein-Vazirani oracle, produces the hidden string .

Quantum Query Algorithms | Understanding Quantum Information & Computation | Lesson 05

This segment shows exactly how the Deutsch-Jozsa circuit solves the Bernstein-Vazirani problem.

Watch the section on the Bernstein-Vazirani problem (here). It starts with the final state from the Deutsch-Jozsa analysis and substitutes in the specific function for the BV problem, showing that the result is simply the state |s\rangle.


4. The Quantum Advantage

The comparison is now stark and clear:

  • Classical algorithm: Requires queries to find the -bit string .
  • Quantum algorithm: Requires only 1 query, regardless of the size of .

This is a proven, significant advantage in query complexity. While the Deutsch-Jozsa algorithm provided an exponential speedup for a promise problem, Bernstein-Vazirani demonstrates a more practical form of speedup by efficiently extracting a hidden piece of information.

From a computer science perspective, this result was one of the first to provide an "oracle separation" between complexity classes. It showed that there is a problem that a quantum computer (in the class BQP, Bounded-error Quantum Polynomial time) can solve efficiently, while a classical probabilistic computer (in the class BPP, Bounded-error Probabilistic Polynomial time) cannot.

The key takeaway is that the quantum algorithm is not trying out all inputs one-by-one. Instead, it uses a single, massive superposition to set up an interference pattern that reveals the hidden structure of the function—the string —all at once.

The Bernstein–Vazirani Algorithm

This final reading summarizes the importance and meaning of the algorithm's advantage.

Read the sections "Why This Matters" and "The Shape of Quantum Advantage". This will help you appreciate that this algorithm is a foundational stepping stone to more powerful algorithms like Shor's algorithm, which also rely on uncovering hidden patterns via quantum interference.



Conclusion

In this lesson, we explored the Bernstein-Vazirani algorithm, a cornerstone of quantum computing that beautifully illustrates quantum advantage. You've seen how it uses the same core components as the Deutsch-Jozsa algorithm—superposition, phase kickback, and interference—to achieve a completely different and more practical goal.

Key Takeaways:

  • The Bernstein-Vazirani problem is to find a hidden -bit string given an oracle that computes .
  • A classical computer requires a minimum of queries to the oracle to determine .
  • A quantum computer can determine with 100% certainty in just a single query.
  • The quantum advantage arises from using the Deutsch-Jozsa circuit structure to encode the hidden string into the phases of a superposition and then using a final set of Hadamard gates to make the only state that survives the interference.

Preview of the Next Lesson:
Now that you have a firm grasp of the theory behind the Bernstein-Vazirani algorithm, the next logical step is to build it. In the next lesson, we will implement the Bernstein-Vazirani algorithm in Qiskit to find the hidden bitstring, turning the circuit diagram you saw today into a working quantum program.