Deutsch–Jozsa Algorithm
The Deutsch–Jozsa problem asks whether a promised Boolean function is constant or balanced. Given a complete coherent XOR-oracle interface, the modern circuit answers exactly with one quantum query by converting the function values into signs and testing the zero-frequency Walsh coefficient. The result is a particularly clean demonstration of phase kickback and interference.
Its complexity lesson requires care. One exact quantum query replaces exact deterministic classical queries, but a bounded-error randomized classical algorithm needs only two queries. The exponential separation is therefore an exact-query result for a deliberately structured black-box promise—not a practical speedup, a runtime theorem, or a separation between BQP and BPP.
Historically, Deutsch and Jozsa’s 1992 formulation used two calls to the function-controlled-NOT operation. The exact one-query network developed here is the 1998 refinement by Cleve, Ekert, Macchiavello, and Mosca.
Required background. Quantum Oracles supplies the complete oracle action, promise and capability distinctions, and construction boundary. Phase Kickback supplies the general XOR-to-phase identity, target-return condition, and phase-sensitive interpretation instantiated here.
Helpful background. Algorithmic Primitives supplies the access–phase–interference–readout pattern. Query Complexity fixes the deterministic, randomized, exact, zero-error, and bounded-error query conventions used below.
The Constant-or-Balanced Promise
Section titled “The Constant-or-Balanced Promise”Fix , write , and let
The legal functions belong to one of two disjoint classes:
Equivalently, regard the truth table as an -bit string. Its promised Hamming weight is , , or , and the required output is the class label constant or balanced. There are
legal functions: two constant truth tables and balanced ones.
This is a promise on which oracle has been supplied, not a guarantee the circuit verifies. An arbitrary off-promise function need not receive a meaningful class label. The input-size conventions also matter: the address length is , while the truth table contains values.
The Ten-Field Deutsch–Jozsa Claim Record
Section titled “The Ten-Field Deutsch–Jozsa Claim Record”Use the chapter’s common algorithm record before interpreting the one-query result. Every field receives a value or a justified N/A; a cost hidden by the oracle model is unspecified, not zero.
- Problem family and size. The family is for , with address length and truth-table size .
- Promise and instance. The supplied Boolean function is constant or has exactly zero values and one values; a finite audit must also state its truth-table order.
- Access and encoding. One query is the complete unitary on an -qubit data register and a one-qubit answer register. Oracle construction and hidden workspace are outside this unit.
- Output and use. Measuring means
constant; every nonzero data word meansbalanced. The output is one promise-class bit, not the truth table or a balanced function’s hidden description. - Success and error. The ideal quantum procedure is exact on every promised instance. Off-promise behavior and noisy finite-shot inference are different contracts.
- Algorithmic idea. Prepare a uniform query state, imprint through a minus-state answer qubit, and use Walsh–Hadamard interference to test whether the mean sign vanishes.
- Executable procedure. Prepare , apply , call once, apply to the data register, measure those qubits, and apply the zero-word decision rule.
- Resource ledger. Count one abstract XOR query, visible logical qubits plus oracle workspace, Hadamards when is supplied, and one -bit measurement. Add one when starting from .
- Classical comparator. Under matched truth-table queries, for exact computation, whereas the fixed-cap two-sided value is .
- Evidence and limits. The circuit and query counts are exact black-box theorems. They do not price oracle construction, gates inside the oracle, memory, noise, fault tolerance, or wall-clock time and do not prove a useful application or BQP BPP.
The remaining sections derive every entry and expose the qualifications that the compact record suppresses.
The Modern One-Query Circuit
Section titled “The Modern One-Query Circuit”Let denote the -qubit data register and the one-qubit answer register, in tensor order . The complete Boolean XOR oracle is
It is a permutation unitary and satisfies . That involution is a mathematical property of this interface; it does not imply that an arbitrary physical implementation is free, elementary, or supplied with additional controlled capabilities.
Starting from , the modern schedule is
Only the data register is measured. The complete schedule contains one call to , irrespective of the number of coherent basis labels in the superposition.
The modern Deutsch–Jozsa network uses one complete XOR-oracle call. The answer qubit returns in while the data register acquires the relative signs ; the final Hadamards test whether their zero-frequency Walsh coefficient vanishes.
A direct phase oracle would give a shorter-looking circuit, but it is a different declared interface. Here the phase action is derived from one call to the complete bit oracle and an explicitly prepared answer state.
Phase Kickback and the Oracle State
Section titled “Phase Kickback and the Oracle State”The answer state
is a eigenstate of the bit flip . Applying the oracle to one data basis state gives
Linearity then gives the post-query state
The answer register returns exactly, carries no residual function value, and factors from the data. What remains is a relative-phase pattern. This is not a readable list of all values: measuring immediately would still return only one uniformly distributed address.
Complementing the function multiplies the entire data state by :
That global sign is unobservable. The two constant functions must therefore lead to the same class decision, as the promise requires.
Walsh–Hadamard Interference
Section titled “Walsh–Hadamard Interference”For bit strings , define the mod-two inner product
The -qubit Hadamard transform acts as
Applying it to the oracle state produces the normalized Walsh coefficients
The factor is , not : one factor of comes from the uniform query state and the other from the final Hadamard transform.
Character orthogonality verifies normalization. Expanding the squared amplitudes gives
The algorithm uses only , but the other coefficients explain the nonzero outcomes. A generic balanced function can distribute probability over several Walsh labels; balance alone does not encode a unique hidden word.
Exact Correctness
Section titled “Exact Correctness”At the zero word, the character factor is one, so
If everywhere, then and the final data state is . If everywhere, then and the state is . In either constant case, measurement returns with certainty. If is balanced, the two cardinalities are equal, , and that outcome is impossible. Therefore
on the promise, with any certifying balance.
Both promise classes are nonempty, so an ordinary zero-query procedure has no information about the label and cannot achieve worst-case success greater than . Under the site’s zero-error convention, a never-wrong zero-query procedure cannot emit either class label, because the same output distribution must serve inputs from both classes. It must therefore report ? with probability one, exceeding the allowed inconclusive probability . The one-query circuit is exact, so under the fixed-cap conventions of the query-complexity owner,
Outside the promise, if , then
This formula describes the circuit’s response to an off-promise truth table. It does not make one shot a test of arbitrary Hamming weight, and it does not certify that the supplier respected the promise.
The Deterministic Classical Query Bound
Section titled “The Deterministic Classical Query Bound”A deterministic exact algorithm queries distinct truth-table entries. It stops and returns balanced as soon as two different values have appeared. If the first answers are identical, the function cannot be balanced, so it returns constant. This gives the upper bound .
The bound is necessary. After any transcript containing at most identical answers, two legal completions remain possible: the queried value can fill the entire table, producing a constant function, or exactly entries can take that value while the unqueried positions supply the opposite value, producing a balanced function. No deterministic decision tree can label both completions correctly from that transcript. Consequently,
This is exponential in the address length and linear in the truth-table size . It is an exact-query theorem. The phrase “classical algorithms require exponentially many queries” is misleading unless the deterministic or zero-error requirement is stated.
The Randomized Classical Comparator
Section titled “The Randomized Classical Comparator”Bounded error changes the picture. For a fixed cap , query distinct uniformly random addresses. A mixed transcript proves the function balanced. For a balanced function, the probability of an all-equal transcript is
where when . On an all-equal transcript, return constant with probability
A constant instance then has error , while a balanced instance has error . The choice of equalizes them:
This risk is minimax optimal. Average any candidate algorithm over permutations of the addresses and over complementation of every truth-table bit. Symmetrization cannot increase its worst-case error. Repeated addresses add no information, and after distinct queries the symmetrized transcript is either mixed, which identifies balance, or all equal, which is compatible with both classes. The only remaining decision probability is ; minimizing gives the value above.
For one query, and . For two,
for every . Hence
The honest comparison is now visible: exact quantum versus exact deterministic queries separates from , whereas bounded-error quantum versus bounded-error randomized queries separates from . The latter has no asymptotic query advantage.
Resources and Implementation Boundaries
Section titled “Resources and Implementation Boundaries”The one-query statement occupies one coordinate in a larger resource ledger:
| Resource | Ideal modern circuit |
|---|---|
| Boolean XOR-oracle calls | |
| visible logical qubits | |
| hidden oracle workspace | unspecified |
| Hadamard gates | if $ |
| additional preparation from $ | 0^{n+1}\rangle$ |
| data measurements | one -bit computational-basis measurement |
| ideal repetitions | |
| oracle gates, width, depth, and cleanup | unspecified |
| routing, fault tolerance, and physical spacetime | unspecified |
| calibration, noise, and wall-clock cost | unspecified |
The two Hadamard layers are parallel across their registers, but total circuit depth includes the oracle depth and the preparation, interference, and readout layers. If an implementation of has gate count , depth , and workspace , calling it one query does not replace those values by one. An arbitrary -entry truth table may itself require resources exponential in to store or synthesize.
Likewise, a query on a superposition is not readable classical evaluations. The circuit returns one class bit under a promise; it neither prints the truth table nor identifies an arbitrary balanced function. A device experiment with a small, transparently compiled instance can test preparation, phase control, interference, and readout while remaining silent about asymptotic total cost.
Classical Information Review owns the comparison once representation, memory construction, output utility, accuracy, and total cost beyond queries are included. Claims, Hype, and Evidence Standards owns the language needed to distinguish an ideal theorem, a finite simulation, a device demonstration, and an end-to-end advantage claim.
Two Worked Claim Audits
Section titled “Two Worked Claim Audits”Exhaustive three-bit promise and spectrum audit
Section titled “Exhaustive three-bit promise and spectrum audit”Take , , and order truth-table positions as 000, 001, 010, 011, 100, 101, 110, 111. Enumerating all promised functions verifies the exact decision criterion. A concrete nonlinear balanced instance is majority on three bits,
with truth-table word 00010111. Its unnormalized Walsh vector, ordered by , is
Because , the final data state is
Each displayed word has probability , and has probability zero. The two constant functions instead give and .
- Problem family and size. This is the member with truth-table entries and legal functions.
- Promise and instance. The exhaustive set contains two constants and seventy weight-four functions; the displayed instance is
00010111in lexicographic address order. - Access and encoding. The register order is three data qubits followed by one answer qubit, and one complete XOR-oracle call implements the displayed truth table abstractly.
- Output and use. The audit checks only the constant-versus-balanced bit. It also records the entire ideal data distribution to test the stronger state calculation.
- Success and error. Every constant has zero-word probability one and every balanced function has zero-word probability zero; the analytic decision error is zero.
- Algorithmic idea. The integer Walsh transform checks cancellation at zero frequency while retaining the nonzero spectrum needed to diagnose the common fixed-output misconception.
- Executable procedure. Enumerate masks through , retain weights , , and , compute all eight signed character sums, divide by eight, and verify norm and zero-word probability.
- Resource ledger. The ideal circuit uses four visible qubits, one query, seven Hadamards, and one three-bit register readout measuring three qubits; an all-zero initialization adds one . Oracle synthesis remains unspecified.
- Classical comparator. At , exact deterministic classification needs five worst-case truth-table queries; this exhaustive software check is verification evidence, not that comparator algorithm.
- Evidence and limits. Node.js v26.4.0 integer enumeration reports promised functions, zero failed norm or decision assertions, and the exact vector above. There is no floating-point or sampling uncertainty.
A compact reproduction of the integer check is:
const N = 8;const parity = (z) => { let p = 0; while (z) { p ^= z & 1; z >>= 1; } return p;};
let promised = 0;let majorityWalsh;for (let mask = 0; mask < 256; mask++) { const f = (x) => (mask >> x) & 1; const weight = Array.from({ length: N }, (_, x) => f(x)) .reduce((a, b) => a + b, 0); if (![0, 4, 8].includes(weight)) continue; promised++; const W = Array.from({ length: N }, (_, y) => Array.from({ length: N }, (_, x) => (f(x) ^ parity(x & y)) ? -1 : 1) .reduce((a, b) => a + b, 0)); if (W.reduce((a, v) => a + v * v, 0) !== N * N) throw Error('norm'); if ((weight === 4) !== (W[0] === 0)) throw Error('decision'); if (mask === 0xe8) majorityWalsh = W;}if (promised !== 72) throw Error('promise count');if (majorityWalsh.join(',') !== '0,4,4,0,4,0,0,-4') throw Error('spectrum');console.log({ promised, majorityWalsh });Eight-input matched-query comparator audit
Section titled “Eight-input matched-query comparator audit”For the same family, the exact quantum and classical values are
The exact fixed-cap minimax sequence is:
| cap | balanced all-equal probability | constant decision probability | worst-case error |
|---|---|---|---|
N/A | |||
- Problem family and size. The comparison concerns with address length three and truth-table size eight.
- Promise and instance. Worst-case success is required over both constant functions and all seventy balanced functions; no input distribution defines the final guarantee.
- Access and encoding. Both models receive matched unit-cost value queries to the same Boolean truth table. The quantum interface is coherent XOR access; the classical interface returns the queried bit.
- Output and use. Each model returns only
constantorbalanced, not a witness, table, or nonzero Walsh label. - Success and error. The quantum result is exact. The randomized comparator has a fixed worst-case cap and two-sided error at most on every promised function.
- Algorithmic idea. Quantum interference tests the signed mean in one call; the randomized algorithm samples distinct positions and randomizes its decision on the ambiguous all-equal transcript.
- Executable procedure. For , choose two distinct addresses uniformly. Return
balancedafter unequal answers; after equal answers, returnconstantwith probability . - Resource ledger. The comparison counts only oracle calls: one coherent quantum query versus two classical value queries. It excludes both implementations, nonquery work, memory, noise, and time.
- Classical comparator. A constant instance succeeds with probability . A balanced instance is all equal with probability , so its error is and its success is also .
- Evidence and limits. A single queried bit has the same uniform marginal under an equal mixture of the two constants and the uniform balanced family, so one query has average success at most and cannot meet the worst-case target. The factor-two bounded-error query gap is not exponential.
The audit deliberately reports both error regimes. Quoting only versus would hide the efficient randomized comparator; quoting only versus would hide the exact-query theorem the algorithm was designed to illustrate.
Historical Formulations and Canonical Ownership
Section titled “Historical Formulations and Canonical Ownership”The familiar circuit is the result of a sequence of refinements. Deutsch’s 1985 one-bit problem introduced a quantum interference procedure whose outcome could be inconclusive with probability . Deutsch and Jozsa generalized the task in 1992 to the constant-versus-balanced promise and obtained an exact quantum advantage, but their network used two calls to the function-controlled-NOT operation. Cleve, Ekert, Macchiavello, and Mosca gave the now-standard exact one-query reconstruction in 1998. The one-call schedule on this page should therefore not be attributed verbatim to the 1992 circuit.
The algorithm also sits at several precise ownership seams. Quantum Oracles owns the interface, extensions, and hidden construction assumptions; Phase Kickback owns the general phase-transduction theorem; Algorithmic Primitives owns the reusable composition pattern; and Query Complexity owns the general measures and lower-bound methods. This page owns their particular composition for the Deutsch–Jozsa promise.
For the affine subfamily
the same Walsh calculation gives
The network then returns the hidden word exactly. Deutsch–Jozsa asks only whether on this restricted family; a general balanced function need not be affine. Bernstein–Vazirani Algorithm owns the hidden-word problem, specialized character proof, and matched one-versus- query comparison.
Simon’s Algorithm instead owns a many-bit value-oracle hidden XOR-period promise, repeated orthogonal-subspace samples, binary-rank recovery and verification, and the matched exponential query separation; it is not a one-shot corollary of Deutsch–Jozsa. Formal class claims, relativization, and the distinction between black-box evidence and BQP versus BPP belong to Quantum Complexity Classes.
Common Deutsch–Jozsa Failures
Section titled “Common Deutsch–Jozsa Failures”Omitting the promise. The zero-word decision is exact only for constant and exactly balanced functions. Off-promise inputs follow the weight-dependent probability law and are not classified by the theorem.
Confusing with . The address has bits, while the truth table has entries. The deterministic exact bound is exponential in but linear in .
Using the wrong normalization. The final amplitude has a factor , and is a mod-two inner product. A factor or an ordinary integer dot product gives the wrong state.
Assigning one balanced output. Only is forbidden for every balanced instance. The remaining probability distribution depends on the full Walsh spectrum.
Treating the two constants as distinguishable. Constant zero and constant one produce states that differ by one global sign. The measurement correctly assigns both to the same class.
Calling superposition bulk readout. One oracle call changes a joint amplitude pattern; one measurement does not expose function values.
Suppressing the randomized comparator. The exponential query separation is exact/deterministic. With error , the matched randomized classical complexity is two.
Calling one query one unit of runtime. Oracle construction, nonquery gates, workspace, memory, compilation, noise, readout, and physical time remain separate resources.
Overstating the history or consequence. The modern one-query network is a 1998 refinement. It proves neither universal necessity of entanglement, practical advantage, nor BQP BPP.
Exercises
Section titled “Exercises”1. Count the promised oracle family
Section titled “1. Count the promised oracle family”For , count the constant and balanced Boolean truth tables. Explain why this count describes a promise on the selected oracle rather than a restriction on the states the algorithm may query.
Solution
There are two constant truth tables, all zero and all one. A balanced truth table is specified by choosing the positions assigned one, giving choices. Thus the promised family has
members. The supplier chooses one unitary from this family. Once chosen, the complete XOR map acts on every computational-basis state and hence on every superposition by linearity; the promise does not confine the query state to a smaller subspace.
2. Verify Boolean phase kickback
Section titled “2. Verify Boolean phase kickback”Apply to . Prove target return and factorization for a general data superposition, then determine the effect of replacing by .
Solution
For a basis state,
Therefore
The common answer state factors exactly. Complementing multiplies every data amplitude by , which is one global phase and cannot affect any measurement probability.
3. Derive the Walsh–Hadamard law
Section titled “3. Derive the Walsh–Hadamard law”Starting from the post-query data state, derive , prove Parseval normalization with character orthogonality, and obtain the zero-word probability for a truth table of arbitrary weight .
Solution
Insert
into . Collecting the coefficient of gives
Since , expanding leaves diagonal terms divided by , hence one. At , there are positive and negative contributions, so
4. Enumerate the three-bit promise
Section titled “4. Enumerate the three-bit promise”Reproduce the exhaustive check and compute the spectrum of the nonlinear balanced truth table 00010111. Why does this example refute the claim that every balanced function produces one deterministic nonzero word?
Solution
There are promised masks. For each mask, compute
The two constant masks have ; all seventy balanced masks have . For 00010111, direct summation gives
Dividing by eight gives amplitudes on , , and , amplitude on , and zero elsewhere. Four different outcomes therefore occur with probability each. Balance forbids only the zero word; it does not determine the rest of the spectrum.
5. Prove the deterministic exact bound
Section titled “5. Prove the deterministic exact bound”Give an executable classical schedule using queries and an indistinguishable-transcript argument showing that no exact deterministic schedule can use fewer in the worst case.
Solution
Query distinct addresses until a mismatch occurs or identical values have been seen. A mismatch proves balance; more than half the table having one value proves constancy under the promise.
For the lower bound, consider any transcript of at most identical answers. It can be completed to a constant table, but it can also be completed to a balanced table by placing the opposite bit in exactly unqueried positions. Both completions follow the same decision-tree path, so no leaf at that depth can be correct on both. Thus
Randomization cannot reduce this count when zero error is required, so .
6. Solve the randomized minimax problem
Section titled “6. Solve the randomized minimax problem”Derive , , and . Evaluate them for and , then prove for every .
Solution
For distinct uniform addresses, a balanced table gives all zeros with probability and all ones with the same probability. Hence
If is the probability of returning constant after an all-equal transcript, the two worst-case errors are for a constant and for a balanced function. Equalizing them gives
For and through , the balanced all-equal probabilities are
the constant-decision probabilities are
and the minimax errors are
Symmetrization over addresses and bit complementation reduces any algorithm to these transcript classes, proving optimality. One query has error , while two have error for every . Therefore .
7. Separate affine structure from balance
Section titled “7. Separate affine structure from balance”For , compute the entire Walsh spectrum. Explain why its deterministic output cannot be generalized to every balanced function.
Solution
Substitution gives
Thus measurement returns with certainty. When , the function is constant; when , it is balanced. For , only of the balanced truth tables are affine, so most can have support on several Walsh labels, as the majority example shows. (For , every balanced truth table happens to be affine.) The hidden-word inference belongs to Bernstein–Vazirani, not to the general Deutsch–Jozsa promise.
8. Complete a ten-field implementation audit
Section titled “8. Complete a ten-field implementation audit”Audit the modern circuit and repair the sentence “one quantum query means the algorithm runs in constant time.” Use every field in the chapter’s claim record.
Solution
- Problem family and size. The task is , with three address bits and eight truth-table entries.
- Promise and instance. The oracle is promised constant or balanced; choose
00010111as the finite balanced instance and state lexicographic address order. - Access and encoding. One licensed query is the complete four-qubit XOR action . Its internal implementation and workspace are not supplied.
- Output and use. The three measured data bits are reduced to
constantwhen they equal000andbalancedotherwise. They are not a dump of eight function values. - Success and error. The ideal promise algorithm succeeds with probability one. Noise, finite-shot inference, and off-promise classification are outside that statement.
- Algorithmic idea. A minus-state target converts one coherent evaluation into the sign pattern , and a Walsh transform tests the signed mean.
- Executable procedure. From , apply four initial Hadamards, one , three final Hadamards on the data, measure the data once, and use the zero-word rule.
- Resource ledger. Count one abstract query, four visible qubits plus hidden workspace, seven Hadamards, three measured bits, and no ideal retry. From , add one . Oracle gates and depth, memory, routing, correction, and time are unspecified.
- Classical comparator. The matched exact deterministic cost is five queries; the matched fixed-cap error- randomized cost is two. The exponential phrasing applies only to the exact family as grows.
- Evidence and limits. The state and counts are exact ideal calculations, with the finite spectrum independently enumerated. They establish neither a constant-time implementation, a gate/runtime advantage, a practical application, nor BQP BPP.
A defensible repair is: “Given unit-cost coherent XOR-oracle access to a promised constant-or-balanced Boolean function on -bit addresses, the modern Deutsch–Jozsa circuit returns the correct class with one exact quantum query; exact deterministic classical decision trees require matched value queries, while bounded-error randomized trees require two. Oracle construction and all nonquery implementation costs are excluded.”
References
Section titled “References”- E. Bernstein and U. Vazirani, “Quantum Complexity Theory,” SIAM Journal on Computing 26, 1411–1473 (1997), doi:10.1137/S0097539796300921.
- R. Cleve, A. Ekert, C. Macchiavello, and M. Mosca, “Quantum Algorithms Revisited,” Proceedings of the Royal Society A 454, 339–354 (1998), doi:10.1098/rspa.1998.0164.
- D. Collins, K. W. Kim, and W. C. Holton, “Deutsch–Jozsa Algorithm as a Test of Quantum Computation,” Physical Review A 58, R1633–R1636 (1998), doi:10.1103/PhysRevA.58.R1633.
- D. Deutsch, “Quantum Theory, the Church–Turing Principle and the Universal Quantum Computer,” Proceedings of the Royal Society A 400, 97–117 (1985), doi:10.1098/rspa.1985.0070.
- D. Deutsch and R. Jozsa, “Rapid Solution of Problems by Quantum Computation,” Proceedings of the Royal Society A 439, 553–558 (1992), doi:10.1098/rspa.1992.0167.
- S. Gulde, M. Riebe, G. P. T. Lancaster, C. Becher, J. Eschner, H. Häffner, F. Schmidt-Kaler, I. L. Chuang, and R. Blatt, “Implementation of the Deutsch–Jozsa Algorithm on an Ion-Trap Quantum Computer,” Nature 421, 48–50 (2003), doi:10.1038/nature01336.
- N. Johansson and J.-Å. Larsson, “Efficient Classical Simulation of the Deutsch–Jozsa and Simon’s Algorithms,” Quantum Information Processing 16, Article 233 (2017), doi:10.1007/s11128-017-1679-7.
- A. Montanaro, “Quantum Algorithms: An Overview,” npj Quantum Information 2, 15023 (2016), doi:10.1038/npjqi.2015.23.
- M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th Anniversary Edition, Cambridge University Press (2010), doi:10.1017/CBO9780511976667.
- D. R. Simon, “On the Power of Quantum Computation,” SIAM Journal on Computing 26, 1474–1483 (1997), doi:10.1137/S0097539796298637.