Deutsch-Jozsa algorithm
A promise-problem algorithm that distinguishes constant from balanced Boolean functions with one coherent oracle query in its standard exact form.
Also called Deutsch–Jozsa algorithm
On this page
Definition and significance
The Deutsch-Jozsa problem assumes that a Boolean function on n-bit strings is either constant or balanced, meaning it returns 1 on exactly half its inputs. The algorithm uses interference to distinguish these two cases. The promise is part of the problem; an arbitrary function need not fall into either category.
The result is historically important as an early separation in query complexity. Its deterministic classical worst-case comparator is exponential in n, but randomized classical testing distinguishes the two promised cases with a small number of queries and bounded error. Calling it an unrestricted exponential advantage would therefore conceal the comparator and error criterion.
Mechanism and mathematical treatment
Prepare |+>^n and a target |->. One reversible oracle call creates 2^(-n/2) sum_x (-1)^f(x)|x>|->. Apply H to each input qubit. The amplitude of outcome y is 2^(-n) sum_x (-1)^(f(x)+x dot y), where dot denotes the binary inner product modulo two. For y=0^n this becomes the average of (-1)^f(x). It has magnitude one for a constant function and is zero for a balanced function.
The remaining outputs need not have a universal distribution. Only the zero-versus-nonzero distinction is used. A deterministic classical algorithm can see identical outputs on 2^(n-1) inputs while both a constant and a balanced completion remain possible, hence needs one additional query in the worst case.
Fully worked reference example
Take n=2 and f(x0,x1)=x0 XOR x1. In order 00,01,10,11, the phase-marked vector is (1,-1,-1,1)/2. It factors as |-> tensor |->. The final H tensor H produces |11>, which certifies the balanced case under the promise. For f=1 everywhere, the vector is -(1,1,1,1)/2 and the final state is -|00>; the minus sign is global, so the observed outcome is 00.
For a function with only one marked input, the zero-output amplitude is (3-1)/4=1/2 and its probability is 1/4. Such an input violates the promise; the algorithm does not magically convert that outcome into a valid constant-or-balanced classification.
Limitations and common misconceptions
The oracle must preserve coherence. Evaluating f separately on classical inputs and assembling outcomes afterward does not implement the algorithm. Small demonstrations normally use explicitly designed simple oracles; that can make them classically easy regardless of the abstract query separation.
Scientific relationships
Promise classification and marked-item retrieval solve different tasks.
Oracle values become phases before the final Hadamard transform.
Historical source context
Deutsch and Jozsa published the foundational paper in 1992. This entry presents the now-standard one-query formulation and independently derives its amplitudes; it does not attribute every modern presentation detail to the original article.
A nonlinear balanced instance with a complete spectrum
Let f(x0,x1,x2)=x0 XOR x1x2. For every fixed pair x1x2, changing x0 flips the function value, so exactly four of the eight inputs have output one. This proves balance without listing all eight values. After phase kickback and the final Hadamards, the sum over x0 forces y0=1. The remaining two-bit transform is that of the AND sign pattern: its amplitudes are 1/2 at y1y2=00,01,10 and -1/2 at 11. Thus the output is (|100>+|101>+|110>-|111>)/2.
The all-zero outcome is absent, as the promise requires, but there is no single deterministic nonzero output. A reader who has seen only linear parity examples might incorrectly infer that every balanced oracle produces a definite string. This nonlinear instance separates the classification guarantee from the detailed spectral distribution. The algorithm's decision rule uses only whether the outcome equals zero; it does not identify the entire truth table.
For comparison, the two balanced functions f=x0 and f=x0 XOR x1x2 both always produce a nonzero result. The first produces |100> with certainty, while the second produces four possible strings. Their query complexity for constant-versus-balanced classification is identical. Their Fourier spectra encode additional structure, but extracting or interpreting that structure is a different problem.
The deterministic and randomized classical comparisons
Let N=2^n. A deterministic classical procedure that has observed the same function value on N/2 distinct inputs still cannot distinguish a constant function from a balanced one whose opposite outputs occupy all remaining positions. One more distinct query resolves the ambiguity. This establishes the N/2+1 worst-case requirement for exact deterministic classification under the promise.
For randomized testing with replacement, query k independently uniform addresses and declare balanced as soon as two different outputs appear. A constant oracle is always classified correctly. For a balanced oracle, the only failure is that all k outputs agree, with probability 2(1/2)^k=2^(1-k). At k=8 the error is 1/128, independent of n. The comparator therefore changes dramatically when a small probability of error is permitted.
Without replacement, the balanced-case failure probability is 2 binomial(N/2,k)/binomial(N,k), as long as k is at most N/2; it is zero above that point. For N=8 and k=3, the failure probability is 2 times 4 divided by 56, or 1/7. Sampling with replacement would give 1/4. The improvement comes from avoiding repeated addresses and from the shrinking same-output population. These exact probabilities provide a fairer explanation than saying only that the classical algorithm needs exponentially many queries.
What happens when the promise fails
Let w be the number of inputs where f=1. The all-zero amplitude is (N-2w)/N, and its probability is (1-2w/N)^2. For N=8 and w=3, the probability is 1/16. A zero result can occur even though the function is not constant; a nonzero result can occur even though it is not balanced. The algorithm has no promised correct label for this input, so either outcome must be reported as the result of an out-of-promise instance rather than forced into a false guarantee.
The formula is symmetric under w and N-w because complementing f changes only a global phase. Consequently this experiment cannot distinguish a sparse set of ones from an equally sparse set of zeros. It measures a squared imbalance, not the sign of the imbalance. An additional value query can identify an output at a selected address, but it does not by itself determine w.
An approximate promise can be formulated, but it requires a new statistical decision rule. If one class has |1-2w/N| at least a specified threshold and another has it at most a smaller threshold, repeated measurements of the zero event estimate a quantity separating the classes. The number of repetitions depends on the resulting probability gap. The exact one-query deterministic statement no longer applies. Preparing and uncomputing the function's reversible implementation still belongs to every coherent repetition.
For the eight-entry example, a classical reference can calculate the complete Walsh transform with twenty-four elementary butterfly additions and subtractions before normalization, or simply enumerate the eight terms. This small calculation checks every output amplitude. It is an explanatory benchmark, not evidence of a computational advantage for a visible three-bit formula.
Sources
Verification scope
Selected source text checked ·
The University of Bristol record confirms the bibliographic details. The entry independently derives the modern one-query formulation.
The source check covered the bibliographic record.
Verification scope
Recorded source check ·
Formal or reference-semantic source anchor only; no SDK execution, hardware run, or empirical advantage is asserted. Original worked examples are independent mathematical constructions.