Let's back up.... Consider the two possible outcomes for the Deutsch-Jozsa algorithm: constant and balanced.
Constant function:
If the function f is constant, it means that it returns the same value (0 or 1) for both input bit strings. Assume it returns 0 for both inputs.
a. Prepare the initial state: |ψ⟩ = |0⟩|1⟩
b. Apply a Hadamard gate (H) to each qubit: (H⨂H)|ψ⟩ = (1/√2)(|0⟩ + |1⟩)⨂(|0⟩ - |1⟩)
c. Apply the oracle gate, which represents the black box function: Uf((H⨂H)|ψ⟩) = (1/√2)(-1)^f(0)(|0⟩ + |1⟩)⨂(|0⟩ - |1⟩)
d. Apply another set of Hadamard gates: (H⨂H)Uf((H⨂H)|ψ⟩) = |x⟩|y⟩, where x is a 2-bit string and y is a single qubit in the state |0⟩ or |1⟩.
e. Measure the input qubits. If the result is |00⟩, then the function f is constant.
Balanced function:
If the function f is balanced, it means that it returns different values (0 and 1) for the two input bit strings. Let's assume it returns 0 for one input and 1 for the other input.
a. Prepare the initial state: |ψ⟩ = |0⟩|1⟩
b. Apply a Hadamard gate (H) to each qubit: (H⨂H)|ψ⟩ = (1/√2)(|0⟩ + |1⟩)⨂(|0⟩ - |1⟩)
c. Apply the oracle gate, which represents the black box function: Uf((H⨂H)|ψ⟩) = (1/√2)(-1)^f(0)(|0⟩ + |1⟩)⨂(|0⟩ - |1⟩)
d. Apply another set of Hadamard gates: (H⨂H)Uf((H⨂H)|ψ⟩) = |x⟩|y⟩, where x is a 2-bit string and y is a single qubit in the state |0⟩ or |1⟩.
e. Measure the input qubits. If the result is any other 2-bit string (e.g., |01⟩ or |10⟩), then the function f is balanced.