Sign in
← Atlas
Strong empiricalAlgorithmsQuantum query algorithm

Bernstein–Vazirani hidden-string circuit

A query circuit that recovers the hidden bit string in f(x) = s · x.

queryhidden stringoracleQiskit

Atlas stars stay in the public catalog. Saving this entry to your workspace starts an unstarred private copy.

Bernstein–Vazirani is a useful companion to Deutsch–Jozsa because it returns the hidden string rather than only its promise class.

Circuit & simulation
secret s100%
What this takes and returns
TakesNothingWhat joins here

No input port at this edge: the record publishes no gate sequence and no register, so there is nothing here to read one off — and unlike a declared hole, nothing has been recorded about what belongs here.

Nothing in the Atlas meets this end.

ReturnsNothingWhat joins here

No output port at this edge: the record publishes no gate sequence and no register, so there is nothing here to read one off — and unlike a declared hole, nothing has been recorded about what belongs here.

Nothing in the Atlas meets this end.

This record publishes no gate sequence and no register, so there is nothing here to read an interface off. Absent rather than empty. See all 152 →

How it works

Bernstein–Vazirani recovers a hidden bit string s{0,1}ns\in\{0,1\}^n from an oracle for the parity function f(x)=sx=isiximod2f(x)=s\cdot x=\bigoplus_i s_i x_i \bmod 2. The circuit prepares the output qubit in |-\rangle and the input register in superposition, queries UfU_f once — phase kickback writes (1)sx(-1)^{s\cdot x} onto x|x\rangle — and applies HnH^{\otimes n} to the input register, which by the Hadamard/Fourier identity collapses it exactly to the basis state s|s\rangle: measuring returns ss with certainty in the ideal circuit. Classically, determining an nn-bit ss from black-box parity queries requires nn queries (one per standard basis vector), so the quantum circuit gives an nn-to-11 query reduction under this promise, not a general search speedup. This record reviews the CX-based parity-oracle construction and its Deutsch–Jozsa-style readout; the one-query claim is scoped to this query/promise model, and oracle-construction and state-preparation costs stay visible rather than folded into the count.

Implementation
Native
bernstein_vazirani.py
from qiskit import QuantumCircuit

secret = '101'
qc = QuantumCircuit(len(secret) + 1, len(secret))
qc.x(len(secret))
qc.h(range(len(secret) + 1))
for index, bit in enumerate(reversed(secret)):
    if bit == '1':
        qc.cx(index, len(secret))
qc.h(range(len(secret)))
qc.measure(range(len(secret)), range(len(secret)))

FINAL_CIRCUIT = qc
Quantum vs classical

Classical baseline

Compare Quantum query algorithm with the strongest classical method for the same instance, input budget, and output metric.

Quantum claim

This reference exposes a quantum circuit pattern; it does not imply an application-level speedup without a matched benchmark.

How to compare

Report input loading, circuit depth, repetitions, classical preprocessing, post-processing, and wall-clock time together.

Declared gaps

Nobody has reviewed this record for gaps yet.

Literature & references
Quantum Computation and Quantum Information: 10th Anniversary Edition2010 · Michael A. Nielsen and Isaac L. Chuang

Standard graduate textbook covering the single- and two-qubit gate definitions, matrix identities, and circuit primitives this record states.

doi.org/10.1017/cbo9780511976667