This is the Deutsch-Jozsa test with an arbitrary uniform-state unitary, and does not require to be a power of two. Choose a known unitary operator such that . Prepare the target qubit in . One Boolean-oracle call gives quantum phase kickback:
Apply to the index register. The amplitude on is
It equals or for the two constant strings, and equals zero for a balanced string. Consequently a single query decides the promised problem exactly: measure the index register and report constant for outcome zero, balanced for any other outcome. This is the Deutsch-Jozsa algorithm with the available exact state-preparation operation.
If , then
so
In either promised case, construct by the one-query procedure in part (a), apply the Walsh-Hadamard transform to its two qubits, and perform a quantum measurement in the computational basis. The outcome is certainly for case (i) and certainly for case (ii). Therefore
This is a two-bit instance of Bernstein-Vazirani phase kickback, and also a promised Deutsch-Jozsa test.
Apply a Hadamard gate to every qubit. The amplitude of becomes
It equals in case (I) and in case (II). A computational-basis measurement therefore returns with certainty in case (I) and never returns it in case (II). This is the Deutsch-Jozsa algorithm.
For the distributed problem, Alice prepares
using one query to her quantum oracle, and sends these qubits to Bob. Bob applies his phase oracle, producing
The function is constant zero in case (1) and balanced in case (2). Bob applies and measures as above: outcome identifies case (1), while every other outcome identifies case (2), with certainty.
For perfect balance, and the all-zero probability is zero. For other balances the one-shot outcomes overlap the constant case. Repeat Deutsch-Jozsa algorithm and declare nonconstant upon any nonzero result. Constants are never misclassified; a -balanced function fails after trials with probability , . It suffices that , using that many oracle calls.