Oracle Algorithms Lab

Hide a function inside a black box, then find out its secret with one quantum query. Step through Deutsch–Jozsa, read a hidden string with Bernstein–Vazirani, and recover a hidden period with Simon’s algorithm by collecting measurements and solving a few equations. Build your own function, break the promise, and compare against the classical count. Everything runs in your browser.

Reviewed December 2026. New to this? Start on the Deutsch–Jozsa tab, pick Constant 0, then press Next five times.

Truth table of f (click a cell to flip it). The promise: f is constant or balanced.

This f has 4 ones out of 8: balanced.

Step 5 of 5: Hadamard on the inputs

Interference: the amplitude of 00…0 is the average of all the signs.

InputAmplitudeChance
|000⟩0.0000.0%
|001⟩0.0000.0%
|010⟩0.0000.0%
|011⟩0.0000.0%
|100⟩0.0000.0%
|101⟩0.0000.0%
|110⟩0.0000.0%
|111⟩1.000100.0%

Result after the last step

Chance of reading 00…0 on the input qubits: 0.00%

Closed form |average of (−1)^f(x)|² = 0.00%

Verdict: balanced. All zeros never.

20 measurements: 111 × 20

The classical side

If f is balanced, the chance that all 3 answers agree (and you wrongly guess constant) is 14.286%.

A guaranteed answer needs 5 queries in the worst case. The quantum circuit asks once.

A five-minute path

  1. Deutsch–Jozsa tab: choose Constant 0 and press Next to the last step. The chance of 00…0 is 100 percent.
  2. Change the function to Balanced: parity. The chance of 00…0 drops to exactly 0. Same circuit, opposite verdict.
  3. Click a few cells in the truth table to break the promise. The chance lands between 0 and 100, and the verdict says so.
  4. Move the classical slider. See how few random queries are enough to be almost sure, and how many a guarantee needs.
  5. Bernstein–Vazirani tab: set a secret and read it back with one query. Flip the offset and see no change.
  6. Simon tab: press Run once until only one candidate remains. Then press New hidden function.

What the lab does and does not do

  • It simulates the full quantum state with perfect gates and an ideal oracle. There is no noise.
  • It counts oracle calls, not running time. Building a real oracle costs gates, and that cost is not counted.
  • For Simon, the lab ignores the second register at measurement. Measuring it first gives the same distribution for the input register.
  • It does not show hardware results. See the Noise Lab for how errors would change the picture.

Reference tables

Computed by the same code as the lab.

Three input bits. Computed by the lab’s simulator.
Function ff(000) … f(111)ClassChance of 000
Constant 00 0 0 0 0 0 0 0constant100.0%
Constant 11 1 1 1 1 1 1 1constant100.0%
Balanced: first bit0 0 0 0 1 1 1 1balanced0.0%
Balanced: parity of all bits0 1 1 0 1 0 0 1balanced0.0%
Balanced: random half (seed 7)0 1 1 0 1 0 1 0balanced0.0%
Chance that k distinct classical queries to a balanced function all return the same bit. Exact product formula.
kn = 3n = 4n = 5n = 6
1100.000%100.000%100.000%100.000%
242.857%46.667%48.387%49.206%
314.286%20.000%22.581%23.810%
42.857%7.692%10.122%11.319%
50 (certain)2.564%4.338%5.282%
80 (certain)0.016%0.245%0.475%
90 (certain)0 (certain)0.082%0.204%
Four input bits. One quantum query returns s with certainty, for either offset b.
Secret sChance of reading s (b = 0)Chance of reading s (b = 1)
0000100.00%100.00%
0001100.00%100.00%
1010100.00%100.00%
1111100.00%100.00%
A hidden two-to-one function with s = 101 (seed 4).
xf(x)x ⊕ s
000110101
001011100
010101111
011100110
100011001
101110000
110100011
111101010
Possible readings y: chance and the check y·s mod 2.
yy·s mod 2Chance
000025.0%
00110.0%
010025.0%
01110.0%
10010.0%
101025.0%
11010.0%
111025.0%
Oracle calls needed. Simon’s classical column is an order of growth, not an exact count.
nDJ classical (guaranteed)BV classical (b = 0)Simon classical (about 2^(n/2))Simon quantum (expected runs)
49444.48
81298168.60
1632,7691625616.61
248,388,609244,09624.61
322,147,483,6493265,53632.61

Eight guides

What is a quantum oracle, and what does counting queries mean?

8 min read

An oracle is a black box that computes a function. Query complexity counts how often you must call it. That is the setting for all three algorithms in this lab.

Phase kickback: how an oracle writes its answer into signs

8 min read

Put the answer qubit in the minus state and the oracle stops changing it. Instead it flips the sign of every input where f is 1. That one trick powers all three algorithms.

Deutsch–Jozsa step by step: one query to tell constant from balanced

10 min read

Follow the amplitudes through the five steps, see why the chance of 00…0 is exactly 1 or 0 under the promise, and what happens when the promise is broken.

Bernstein–Vazirani step by step: reading a hidden string in one query

9 min read

The same circuit as Deutsch–Jozsa, applied to a different promise, returns a whole n-bit secret with certainty. See why the Hadamard layer is a decoder.

Simon’s algorithm step by step: finding a hidden period

11 min read

Each run of the circuit yields a random string orthogonal to the secret. Collect about n of them, solve a small linear system, and the secret appears. Classically this takes exponentially many queries.

Classical against quantum query counts: reading the scaling table

8 min read

How many oracle calls each problem needs as n grows, with the exact formulas used by the lab and the one place where an estimate replaces an exact count.

What a query advantage does and does not mean

9 min read

Deutsch–Jozsa looks exponential but a randomised classical algorithm solves it in a few queries. Here is the honest reading of all three results.

Running Deutsch–Jozsa and Bernstein–Vazirani in code

7 min read

Short Qiskit sketches of the circuits in this lab, labelled clearly as not run here, and a checklist for verifying them against the lab’s numbers.

Predict, then check

For three input bits and f = the parity of all bits, what is the chance of reading 000?

0%. The function is balanced, so the amplitude of 000 is the average of equal numbers of +1 and −1 signs. The simulator gives 0.0%.

A balanced function on 4 bits is queried at 3 distinct random inputs. How often do all three answers agree?

20.0% of the time. After 9 queries the chance is 0, because only 8 inputs can share a value.

Bernstein–Vazirani with s = 101101 and offset b = 1. What does one query return?

101101 with probability 100%. The offset only changes a global phase.

Simon with n = 3 and s = 110. Which readings y can appear?

Those with y·s = 0 mod 2: 000, 001, 110, 111. Each has probability 25%.

In Deutsch–Jozsa, how large is the chance of 0000 for a 4-bit function with exactly 4 ones among 16 inputs?

((12 − 4)/16)² = 25%. The function is neither constant nor balanced, so the promise is broken. The simulator gives 25.0%.

About how many runs does Simon’s algorithm need on average for n = 8?

About 8.60, to collect 7 independent equations. This page’s own arithmetic from the spanning-time sum.

Related on QuantumAtlas

Frequently asked questions

What is an oracle in quantum computing?

A black-box function you can call but not read. Algorithms are compared by how many calls they need. The three problems in this lab, Deutsch–Jozsa, Bernstein–Vazirani and Simon, are the classic oracle problems.

What does the Deutsch–Jozsa algorithm decide?

Whether a function on n bits is constant or balanced, given a promise that it is one or the other. One quantum query decides it. A classical algorithm needs 2^(n−1) + 1 queries to be certain.

Is Deutsch–Jozsa really exponentially faster?

Only against a classical algorithm that must be certain. A randomised classical algorithm that accepts a tiny error chance needs just a few queries, as the lab’s classical slider shows. The gap is real but not practical.

What is phase kickback?

With the answer qubit in the minus state, the oracle leaves it unchanged and flips the sign of every input where f is 1. The result is a sign pattern on the inputs that a Hadamard layer can read.

What does Bernstein–Vazirani find?

A hidden n-bit string s, from a function f(x) = s·x ⊕ b. One quantum query returns s with certainty. A classical algorithm needs about n queries.

Why does the offset b not matter to the quantum circuit?

It only multiplies the whole state by −1, a global phase that no measurement can detect.

What is Simon’s algorithm for?

Finding a hidden period s of a two-to-one function with f(x) = f(x ⊕ s). Each run gives a random string orthogonal to s. About n runs and a small linear solve recover s. Classically it needs about 2^(n/2) queries.

Why did Simon’s algorithm matter?

It gave an exponential gap against randomised classical algorithms, and its period-finding idea led to Shor’s algorithm.

Is the simulation exact?

Yes. The lab simulates the full state vector, up to 7 qubits for Deutsch–Jozsa, 9 for Bernstein–Vazirani and 10 for Simon, with no approximation. The random samples use a seeded generator, so they repeat.

Where can I build these circuits myself?

In the Circuit Builder, which has Deutsch–Jozsa and Bernstein–Vazirani examples, or in code using the Qiskit lesson.

Sources and further reading

References were written from memory of the original works. Check the originals for exact citations.