← Atlas

Algorithms · Quantum query algorithm

Bernstein–Vazirani hidden-string circuit

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

Strong empiricalUpdated

View frozen graph

A small worked example, computed in your browser. It is not a result from this record's papers.

Bernstein-Vazirani recovers a secret string

4 input qubits, secret string 1011, recovered in a single query.

q0q1q2q3q4Step 1 of 6 · XXStep 2 of 6 · Hadamard layer(5)Hadamard layer(5)Step 3 of 6 · BV oracle(1011)BV oracle(1011)Step 4 of 6 · Hadamard layer(4)Hadamard layer(4)Step 5 of 6 · HHStep 6 of 6 · XX

Step 1 of 6 · X

Probability of each outcome after this step

  • 10000100%
  1. Sets the ancilla to |1⟩, so the next step can put it into |−⟩.

    The whole state moves from 00000 to 10000 — one certain outcome before, one certain outcome after, no superposition either side.

  2. Hadamards everything: the ancilla becomes |−⟩, and the four input qubits spread into an equal superposition.

    Probability spreads from 1 outcome to 32. All 32 are equally likely.

  3. CXs the input qubits where the secret has a 1 (positions 0, 1 and 3) onto the ancilla, kicking back a phase that encodes the secret.

    The outcome probabilities do not move at all. What this step changes is phase — 2 distinct relative phases across the state now — which no measurement can see until a later step turns it back into probability.

  4. A second Hadamard layer on the inputs turns that phase pattern directly into the secret string.

    Probability gathers from 32 outcomes onto 2. 01011 goes from 3.1% to 50.0%.

  5. Undoes the ancilla's Hadamard.

    Probability gathers from 2 outcomes onto 1. 11011 goes from 50.0% to 100.0%.

  6. Returns the ancilla to |0⟩, purely for a tidy final state.

    The whole state moves from 11011 to 01011 — one certain outcome before, one certain outcome after, no superposition either side.

Readout The four input qubits read 1011, the secret, recovered exactly, in one shot. The ancilla reads 0.

Open in Studio
  • Steps3
  • Wires4
  • Qubitsn + 1
  • Depthoracle-dependent
  • Queries1
  • Papers1

Bernstein–Vazirani recovers a hidden bit string s∈{0,1}ns\in\{0,1\}^n from an oracle for the parity function f(x)=s⋅x=⨁isixi mod 2f(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)s⋅x(-1)^{s\cdot x} onto ∣x⟩|x\rangle — and applies H⊗nH^{\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.

References

Strong empirical
  • Verified by construction
  • Textbook / standard citation
Method
Construct a parity oracle for a fixed secret string and inspect the Deutsch–Jozsa-style readout.
Result
The ideal circuit returns the encoded secret string with one oracle query.
Caveat
The one-query claim is for the promise/query model; state preparation, oracle construction, and readout costs remain visible.
Quantum Complexity Theory ↗
Kind
curated reference
Reviewed by
Leona Quantum curation pass
License
CC BY 4.0-compatible reference metadata
queryhidden stringoracleQiskit

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