QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
02 · Bernstein–Vazirani: read a hidden string0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 202Quantum Algorithms·Lesson 2 of 5

Bernstein–Vazirani: read a hidden string

Same circuit shape, more useful result: recover an n-bit secret with one query.

Intermediate10 min read4 sections · 2 questions+45
By the end you will be able to
  1. 01Build the oracle for a given secret s.
  2. 02Explain why the output register reads s exactly.
fs​(x)=s⋅xmod2,H⊗n(2n​1​x∑​(−1)s⋅x∣x⟩)=∣s⟩
The oracle is one CNOT from each input bit where s has a 1 onto the target. After the final Hadamards the register is exactly |s⟩, deterministically.
Hands-on

Secret s = 101

Simulate: every shot reads 101. Change which CNOTs are present to encode another secret and watch the histogram follow.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[4] q;
bit[3] c;
x q[3];
h q[0];
h q[1];
h q[2];
h q[3];
barrier q;
cx q[0], q[3];
cx q[2], q[3];
barrier q;
h q[0];
h q[1];
h q[2];
c[0] = measure q[0];
c[1] = measure q[1];
c[2] = measure q[2];
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground

Classically you need n queries (one per bit: query with x = 0…010…0). Quantumly one. Unlike Deutsch–Jozsa the gap holds even against randomised classical algorithms, which is why Bernstein–Vazirani is the first 'real' separation in the oracle model.

Knowledge check

2 questions · one try each counts

Question 1

With secret s = 011 (s0 = 1, s1 = 1, s2 = 0), which CNOTs form the oracle?

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

A secret s has 50 bits. How many oracle queries does each side need to learn all of s for certain?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

Bernstein–Vazirani turns the Deutsch–Jozsa template into a deterministic n-to-1 query advantage: the Hadamard transform of the kicked-back phases is the secret itself.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 3 · 14 min
Grover's search
Amplitude amplification: find a marked item in √N steps, and why you must stop at the right time.
More in Quantum Algorithms
  • Deutsch–Jozsa: one query instead of many
  • QFT and phase estimation
  • Shor's algorithm: the overview
Deutsch–Jozsa: one query instead of manyGrover's search
In this lesson0%
  1. Introduction
  2. Try it: Secret s = 101
  3. Knowledge check
  4. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in