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

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.

8 min read · reviewed December 2026

A function you can call but not read

Every algorithm in this lab starts from the same setup. Someone hides a function f that takes an n-bit string x and returns one bit, or in Simon’s case an n-bit string. You may call it as often as you like, but each call is counted, and you may not look inside. The hidden function is called an oracle, after the old idea of a source that answers questions without explaining how.

The setting is artificial on purpose. It strips away everything about how f is built and leaves one clean question: how many calls does it take to learn a certain fact about f? The answer is the query complexity of the problem. Because only calls are counted, you can prove statements about it that are very hard to prove for real running time.

How a quantum computer calls an oracle

A classical call takes an input x and returns f(x). A quantum computer needs a reversible version, because quantum gates are reversible. The standard form uses two registers: an input register holding x and an answer register holding a bit y. The oracle maps |x⟩|y⟩ to |x⟩|y ⊕ f(x)⟩, where ⊕ is addition modulo 2. The input is left alone, and f(x) is added into the answer.

Nothing stops you from feeding the oracle a superposition of inputs. If the input register holds a sum of many x values, the oracle acts on all of them in one call and returns a state in which each x is paired with its own f(x). That is the sense in which a quantum computer evaluates f on many inputs at once. It is not yet a useful answer, because measuring gives only one pair. The three algorithms in this lab show how to arrange interference so that a single call yields a global property of f.

|x⟩|y⟩ → |x⟩|y ⊕ f(x)⟩

Three problems, three promises

Each problem comes with a promise about f. The algorithm may rely on the promise, and nothing is claimed if the promise is broken.

  • Deutsch–Jozsa: f takes n bits to one bit and is either constant (the same answer for every input) or balanced (0 for exactly half the inputs and 1 for the other half). Decide which.
  • Bernstein–Vazirani: f(x) = s·x ⊕ b for a hidden string s. Find s.
  • Simon: f takes n bits to n bits and f(x) = f(x ⊕ s) for a hidden non-zero s, with no other collisions. Find s.

What the lab counts

The Query counts tab shows how many oracle calls a classical algorithm needs against a quantum one for each problem. Treat those numbers as statements about this model, not about real computers. The guide on what a query advantage does and does not mean explains the limits.

Query complexity counts calls to the box. It says nothing about how long the box takes to run, or how hard it is to build.

Try it

Questions

Is an oracle a real device?

No. It is a modelling device. In practice the oracle is a circuit you build from the problem’s own data, and building it costs time that the query count ignores.

Why must the oracle be reversible?

Quantum evolution is reversible, so a quantum oracle must be too. Writing f(x) into a separate answer register, instead of overwriting x, keeps the map reversible.

Read next

Sources and further reading

Check the original sources for exact citations.