Query a known set of inputs and store its output table. If no function collision occurs there, each of its distinct outputs has exactly one partner in the complement, for a two-to-one function. A compute-phase-uncompute construction marks those partners using two function queries and reversible table comparison. Known-subset Grover search then uses such phase queries. Including table preparation and a final verification query gives
Choosing balances both terms and gives . The Grover rotation angle rounding bound gives success tending to one. This is a query bound; it does not make reversible table lookup free in a gate or physical-memory cost model.
The product of the data Pauli Z gates has computational-basis eigenvalue
Use the parity circuit from part (ii), apply the target unitary gate , and then uncompute the parity with . For every basis input,
This equals on the data, with the ancilla qubit returned to zero. The compute-phase-uncompute construction therefore gives an exact linear-size circuit:
This is a Pauli-string phase by parity computation, an instance of simulation of a computable diagonal Hamiltonian. Part (i) also explains it by , whose exponential restricts correctly to the target- subspace. If no extra line is desired, accumulate parity into the last data qubit, apply there, and undo the CNOT gates, for gates. Both constructions implement the global phase as well as the relative phases exactly.
Interpret a function collision as two distinct inputs with equal outputs. Without distinctness the request is vacuous, since an input paired with itself always qualifies. Set (handling small by direct queries), choose a known set of size , and query all its inputs. Store a classical table of their outputs and corresponding inputs. If this table contains a function collision, return it immediately.
Otherwise the table contains distinct outputs. Because is exactly two-to-one, each has exactly one partner in , the known complement of . None lies in , and different table outputs have different partners. Thus exactly inputs in , of size , satisfy the known-table membership predicate
Build a marked-state phase oracle for this predicate by a compute-phase-uncompute construction: use on a clean answer quantum register, reversibly compare its output against the classical table, apply the conditional minus sign, undo the comparison, and apply again. Since the answer operation is bitwise exclusive or, . All workspace returns to zero, and each phase query costs two calls to .
Perform known-subset Grover search in the span of the computational basis states labelled by , starting in their uniform superposition state. Reflection about this known state uses no queries; choosing as an initial interval makes a known interval that can also be encoded by its own labels. Its marked fraction is , so the previous Grover rotation angle analysis uses phase queries. On measuring , one further query checks the output and retrieves its partner from the table. The inputs are distinct because the two sets are disjoint.
Consequently the quantum query complexity is
For large , rounding the optimal Grover search algorithm iteration count gives success at least . An internal table function collision already gives certain success. The balance explains the cube-root choice. This is the Brassard–Høyer–Tapp collision algorithm: its table uses classical bits. The bound counts calls to , as requested; it does not charge table lookup and its reversible implementation as constant-time gates, or claim an overall polynomial time in .
Let the known phase gate on the answer register be
where the comparison uses ordinary integers, not modular arithmetic. A reversible circuit computes the predicate, applies a Pauli Z gate to its flag, then performs uncomputation.
The compute-phase-uncompute construction now gives
Use modular-oracle inversion by negation to realize the last operation with one further query. Exactly two oracle queries implement , returning the answer register and comparison workspace to their initial states.
Since , the spectral decomposition gives
Replace the middle gate of the previous compute-phase-uncompute construction by
a one-qubit rotation about the z-axis. Then
The circuit uses the gates of , their inverses, and one fixed rotation; it returns the quantum ancilla to . The same construction implements with middle gate , an instance of simulation of a computable diagonal Hamiltonian.
Use a clean quantum ancilla and apply the quantum circuit , then the Pauli Z gate on the ancilla, then the inverse quantum circuit :
This compute-phase-uncompute construction implements on every input with the ancilla initially , and by linearity on any superposition of those inputs. The action on ancilla- inputs need not coincide with ; the question only requires the clean-ancilla subspace.
With the restricted operations, begin in and apply to the first register:
Now apply
For every basis state this compute-phase-uncompute construction acts as
The first register is therefore the same phase state used in part (a). Apply and measure. Again, outcome occurs with probability one for a constant string and probability zero for a balanced string. The construction uses exactly two queries to and only the permitted operations.
The Pauli Z gates give eigenvalue on . Use parity computation by CNOT gates to put the parity bit in a zero ancilla, apply to it, and uncompute. The data acquire exactly , and the ancillary line returns to zero. This compute-phase-uncompute construction needs one- and two-qubit gates. Accumulating parity into the last data line instead uses gates without an extra ancilla. Neither implementation drops the global phase.