Constant vs Balanced Functions
The Deutsch–Jozsa algorithm is one of the earliest demonstrations that a quantum computer can answer a specific question with exponentially fewer queries than any classical algorithm. Before we can appreciate what the algorithm does, we need to be precise about the kind of function it reasons about.
Boolean functions with a single-bit output
A Boolean function on bits is any map . It takes an -bit string as input and outputs a single bit. The Deutsch–Jozsa problem restricts attention to functions with a particular structure, so we need two definitions.
Constant function. A function is constant if it returns the same output for every input:
There are exactly two constant functions on bits — the all-zeros function and the all-ones function.
Balanced function. A function is balanced if exactly half of all inputs map to and the other half map to . Because there are possible inputs, a balanced function outputs on exactly of them and on the remaining .
Why this classification matters
Classically, determining whether an unknown is constant or balanced requires querying on at least inputs in the worst case. You must see just over half of all outputs before you can be certain: if the first queries all return , the function could still be balanced (the other half might all be ) or constant (all outputs are ). Only the next query settles it. For large this is an exponential number of queries.
The Deutsch–Jozsa algorithm, by contrast, answers the question with a single quantum query regardless of . The separation is as stark as possible: one query versus exponentially many. This is possible because the algorithm uses a quantum-mechanical encoding of (called an oracle) that allows all inputs to be queried simultaneously through superposition, then uses interference to read out a global property — constant or balanced — in one shot.
Concrete small examples
For the four possible inputs are , , , and .
| Function | | | | | Type | |----------|---------|---------|---------|---------|------| | | 0 | 0 | 0 | 0 | constant | | | 1 | 1 | 1 | 1 | constant | | | 0 | 0 | 1 | 1 | balanced | | | 0 | 1 | 0 | 1 | balanced |
and each output on exactly two of the four inputs and on the other two, so both are balanced. The Deutsch–Jozsa algorithm can distinguish the top two rows from the bottom two with a single oracle call, no matter how large the table grows.
From classification to algorithm
The module that follows shows how to encode as a quantum oracle — a unitary gate that computes reversibly — and then how to run the Deutsch–Jozsa circuit. The circuit's output is deterministically when is constant and anything else when is balanced, giving a one-shot answer to a question that classically demands exponentially many queries.
Sign in on the full site to ask questions and join the discussion.