In short

This is the multi-qubit practice chapter. You have met the CNOT, the Toffoli, Bell states, GHZ states, SWAP, controlled-Z, and the basic circuit identities. Below are eight worked problems that compose those pieces into short, recognisable circuits — build every Bell state from |00\rangle, build GHZ from |000\rangle, construct SWAP from three CNOTs, build controlled-Z from a CNOT sandwiched between two Hadamards, trace a mystery circuit step by step, and preview an oracle-based algorithm. Each problem comes with the input state, a hint, a step-by-step solution, a labelled circuit SVG, and a one-line Qiskit snippet for verification. Five self-test problems at the end let you check your fluency. The chapter is the multi-qubit counterpart to the Single-Qubit Practice article — same rhythm, same expectations, more qubits.

Note: Interactive version coming soon

An interactive drag-a-gate, multi-qubit circuit-builder widget — where you place gates on wires, hit "run," and see the state-vector update in real time — is planned for a future version of padho-wiki. Until it ships, this article is the pen-and-paper (or Qiskit) equivalent: every problem solved with matrix algebra, every circuit drawn as a labelled SVG, every answer verifiable with a two-line Qiskit script.

You have spent several chapters building the multi-qubit toolkit. CNOT entangles two qubits. Toffoli adds a third control for reversible AND. Bell states are the four maximally entangled two-qubit states. GHZ and W states are three-qubit entangled states of two very different kinds. SWAP exchanges qubits; controlled-Z phases the |11\rangle component; circuit identities tell you which gate sequences are equivalent.

Now you put them together. The problems below are canonical constructions — the kind of thing you need to write down in forty seconds on a whiteboard without looking anything up. Each one has a cleanly stated input, a cleanly stated output, and a short solution. Some can be solved with one gate; some need three; two require the full grammar of multi-qubit circuits.

A reminder on conventions before you start. Circuits are drawn left to right in time — the leftmost gate is applied first. The matrix product runs right to left — the leftmost matrix is applied last. Qubit ordering in kets like |q_1 q_0\rangle: the rightmost bit is qubit 0 (Qiskit convention). This wiki follows the Nielsen & Chuang convention where top wire in a circuit is qubit 0 and appears leftmost in the ket — |q_0 q_1\rangle. When you work a problem in Qiskit, double-check which convention the example uses.

The eight problems

The problems are arranged in increasing composition depth — Problem 1 uses two gates; Problem 8 introduces an oracle and previews what a quantum algorithm looks like.

Problem 1: Build $|\Phi^+\rangle$ from $|00\rangle$

Given: |00\rangle = |0\rangle \otimes |0\rangle, the trivial two-qubit state.

Target: the Bell state |\Phi^+\rangle = \tfrac{1}{\sqrt 2}(|00\rangle + |11\rangle) — the prototype entangled state of two qubits.

Hint: first put qubit 0 into an equal superposition; then entangle the two qubits with a CNOT.

Step 1. Apply H to qubit 0. Under H, |0\rangle \mapsto \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle). Qubit 1 stays in |0\rangle. The joint state becomes

H \otimes I \;|00\rangle = \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle) \otimes |0\rangle = \tfrac{1}{\sqrt 2}(|00\rangle + |10\rangle).

Why H on qubit 0: the target has nonzero amplitude on both |00\rangle and |11\rangle, so some amplitude must flow from |0\rangle to |1\rangle on the control qubit. H is the minimum-depth gate that produces an equal-amplitude |0\rangle + |1\rangle superposition, which is exactly what you need.

Step 2. Apply CNOT with qubit 0 as control and qubit 1 as target. CNOT flips qubit 1 iff qubit 0 is |1\rangle, so

\text{CNOT} \cdot \tfrac{1}{\sqrt 2}(|00\rangle + |10\rangle) = \tfrac{1}{\sqrt 2}(|00\rangle + |11\rangle) = |\Phi^+\rangle.

Why CNOT: it is the minimum entangling operation. Without a two-qubit gate, you can only ever build product states — |\psi_0\rangle \otimes |\psi_1\rangle — and the Bell states are not product states. The CNOT takes the |10\rangle branch of the superposition (control = 1) and flips the target, producing |11\rangle; it leaves the |00\rangle branch alone. The two branches of amplitude 1/\sqrt 2 are now correlated — measurement of one determines the other, which is the essence of entanglement.

Result. Two gates: H on qubit 0, then CNOT with qubit 0 controlling qubit 1.

Build |Phi+⟩ from |00⟩A two-qubit circuit. Top wire q0 starts |0⟩, passes through an H gate, then becomes the control dot of a CNOT. Bottom wire q1 starts |0⟩ and becomes the target of the CNOT. The output state is labelled |Phi+⟩.|0⟩|0⟩q₀q₁H|Φ⁺⟩H then CNOT — the canonical Bell-state factory.
The two-gate Bell-state factory. $H$ on qubit $0$ creates a $|00\rangle + |10\rangle$ superposition; CNOT turns the $|10\rangle$ into $|11\rangle$, producing $\tfrac{1}{\sqrt 2}(|00\rangle + |11\rangle) = |\Phi^+\rangle$.

Qiskit one-liner: qc = QuantumCircuit(2); qc.h(0); qc.cx(0, 1).

Problem 2: Build $|\Phi^-\rangle$ from $|00\rangle$

Given: |00\rangle.

Target: |\Phi^-\rangle = \tfrac{1}{\sqrt 2}(|00\rangle - |11\rangle) — the Bell state with a minus sign.

Hint: the minus sign is a relative phase between |00\rangle and |11\rangle. Either prepare the control with a |0\rangle - |1\rangle superposition instead of |0\rangle + |1\rangle, or take Problem 1's output and add a Z.

Step 1. Apply X then H to qubit 0. X|0\rangle = |1\rangle; H|1\rangle = |-\rangle = \tfrac{1}{\sqrt 2}(|0\rangle - |1\rangle). The joint state becomes

(H \otimes I)(X \otimes I)|00\rangle = \tfrac{1}{\sqrt 2}(|00\rangle - |10\rangle).

Why X first and not just H: applying H directly to |0\rangle gives |+\rangle = \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle), which produces |\Phi^+\rangle after CNOT. To get |\Phi^-\rangle you need the minus sign, and starting from |1\rangle (after an X) gives |-\rangle after H, which threads the minus sign through the CNOT onto the |11\rangle branch.

Step 2. Apply CNOT with qubit 0 as control. The CNOT flips qubit 1 whenever qubit 0 is |1\rangle, but it does not touch the amplitudes — so the minus sign on |10\rangle survives onto |11\rangle:

\text{CNOT} \cdot \tfrac{1}{\sqrt 2}(|00\rangle - |10\rangle) = \tfrac{1}{\sqrt 2}(|00\rangle - |11\rangle) = |\Phi^-\rangle.

Result. Three gates: X, then H, then CNOT — all on the obvious wires.

Build |Phi-⟩ from |00⟩Two-qubit circuit with X, H, CNOT (in that order) on top wire q0 and CNOT target on bottom wire q1. Output labelled |Phi-⟩.|0⟩|0⟩XH|Φ⁻⟩X flips the control to |1⟩ first; H then produces |−⟩; CNOT entangles.
Three-gate recipe for $|\Phi^-\rangle$. Equivalent recipes exist — e.g., $H$-then-CNOT-then-$Z$ on qubit $0$ — but the $X$-then-$H$-then-CNOT pattern cleanly shows where the minus sign enters.

Qiskit one-liner: qc = QuantumCircuit(2); qc.x(0); qc.h(0); qc.cx(0, 1).

Problem 3: Build $|\Psi^+\rangle$ and $|\Psi^-\rangle$

Given: |00\rangle.

Targets: |\Psi^+\rangle = \tfrac{1}{\sqrt 2}(|01\rangle + |10\rangle) and |\Psi^-\rangle = \tfrac{1}{\sqrt 2}(|01\rangle - |10\rangle).

Hint: |\Psi^\pm\rangle have support on |01\rangle and |10\rangle — opposite bit-strings, not equal ones. Flip qubit 1 at the end.

Step 1. For |\Psi^+\rangle: build |\Phi^+\rangle first (H then CNOT, as in Problem 1), then apply X to qubit 1:

(I \otimes X)\,|\Phi^+\rangle = \tfrac{1}{\sqrt 2}(|01\rangle + |10\rangle) = |\Psi^+\rangle.

Step 2. For |\Psi^-\rangle: build |\Phi^-\rangle first (Problem 2), then apply X to qubit 1:

(I \otimes X)\,|\Phi^-\rangle = \tfrac{1}{\sqrt 2}(|01\rangle - |10\rangle) = |\Psi^-\rangle.

Why an X on qubit 1 converts |\Phi\rangle to |\Psi\rangle: the difference between |\Phi\rangle and |\Psi\rangle states is whether the two bit-values are correlated (both same) or anti-correlated (opposite). Flipping just qubit 1 changes "both 0 or both 1" into "0 and 1 or 1 and 0." The sign stays where it was because X acts linearly and does not touch amplitudes.

Result. To build |\Psi^+\rangle: H on qubit 0, CNOT with qubit 0 controlling qubit 1, X on qubit 1. To build |\Psi^-\rangle: the same plus an X on qubit 0 at the very start (to thread the minus sign in, exactly as in Problem 2).

Build |Psi+⟩ from |00⟩Two-qubit circuit: H on q0, CNOT q0-q1, X on q1. Output |Psi+⟩.|0⟩|0⟩HX|Ψ⁺⟩H + CNOT make |Phi+⟩; trailing X on q₁ converts it to |Psi+⟩.
$|\Psi^+\rangle$ is built as $|\Phi^+\rangle$ with an extra $X$ on qubit $1$ at the end. The same trick ($|\Phi^-\rangle$ plus $X$ on qubit $1$) gives $|\Psi^-\rangle$.

Qiskit one-liner (for |\Psi^+\rangle): qc.h(0); qc.cx(0, 1); qc.x(1).

Problem 4: Build $|\text{GHZ}\rangle$ from $|000\rangle$

Given: |000\rangle, a three-qubit state.

Target: the GHZ state |\text{GHZ}\rangle = \tfrac{1}{\sqrt 2}(|000\rangle + |111\rangle).

Hint: same structure as the Bell state, but with one extra CNOT cascading the control.

Step 1. Apply H to qubit 0. The state becomes \tfrac{1}{\sqrt 2}(|000\rangle + |100\rangle).

Step 2. Apply CNOT with qubit 0 as control and qubit 1 as target. The state becomes \tfrac{1}{\sqrt 2}(|000\rangle + |110\rangle).

Step 3. Apply CNOT with qubit 0 as control and qubit 2 as target. (Alternatively, qubit 1 could control qubit 2; either works because once qubits 0 and 1 are correlated, controlling from either one produces the same three-way correlation.) The state becomes

\tfrac{1}{\sqrt 2}(|000\rangle + |111\rangle) = |\text{GHZ}\rangle.

Why cascade CNOTs: the GHZ state has three qubits perfectly correlated — measuring any one determines the other two. Each CNOT threads the control's bit-value into one more target qubit, extending the correlation by one qubit per CNOT. For n-qubit GHZ, you need n-1 CNOTs (or a shallower \log n-depth tree — see the Going Deeper section of GHZ and W states).

Result. Three gates: H on qubit 0, CNOT(0 \to 1), CNOT(0 \to 2).

Build GHZ state from |000⟩Three-qubit circuit. Top wire q0 gets H, then controls two CNOTs, to q1 and q2. Output is GHZ.|0⟩|0⟩|0⟩H|GHZ⟩One H + two CNOTs — linearly extending the Bell recipe to three qubits.
The GHZ factory. One Hadamard puts qubit $0$ into superposition; two cascading CNOTs propagate the correlation to qubits $1$ and $2$. Adding more CNOTs extends the pattern to $n$-qubit GHZ.

Qiskit one-liner: qc = QuantumCircuit(3); qc.h(0); qc.cx(0, 1); qc.cx(0, 2).

Problem 5: Trace a mystery circuit

Given: the two-qubit circuit shown below: starting from |00\rangle, apply H to qubit 0, then apply H to qubit 1, then apply CNOT with qubit 0 controlling qubit 1.

Target: work out the final state.

Hint: first apply the two Hadamards in parallel to get a uniform four-way superposition; then apply CNOT.

Step 1. H \otimes H on |00\rangle.

H|0\rangle = \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle), \quad (H \otimes H)|00\rangle = \tfrac{1}{2}(|0\rangle + |1\rangle)(|0\rangle + |1\rangle) = \tfrac{1}{2}(|00\rangle + |01\rangle + |10\rangle + |11\rangle).

Step 2. Apply CNOT. Recall CNOT flips qubit 1 iff qubit 0 is |1\rangle. So:

  • |00\rangle \mapsto |00\rangle
  • |01\rangle \mapsto |01\rangle
  • |10\rangle \mapsto |11\rangle
  • |11\rangle \mapsto |10\rangle

Applying CNOT to the full superposition:

\text{CNOT} \cdot \tfrac{1}{2}(|00\rangle + |01\rangle + |10\rangle + |11\rangle) = \tfrac{1}{2}(|00\rangle + |01\rangle + |11\rangle + |10\rangle).

Why the final state is the same as the intermediate one: CNOT permuted the four basis states, taking |10\rangle \leftrightarrow |11\rangle. But the coefficients on |10\rangle and |11\rangle were both 1/2 before the CNOT, so the permutation left the sum unchanged.

Step 3. The final state is the uniform superposition over all four basis states:

\tfrac{1}{2}(|00\rangle + |01\rangle + |10\rangle + |11\rangle) = |+\rangle \otimes |+\rangle.

In other words, applying H to each qubit, then CNOT, gives the same state as just applying H to each qubit — the CNOT was redundant for this particular input. This is a famous circuit identity: \text{CNOT}\,(H \otimes H)|00\rangle = (H \otimes H)|00\rangle.

Result. Final state: \tfrac{1}{2}(|00\rangle + |01\rangle + |10\rangle + |11\rangle), i.e., |+\rangle \otimes |+\rangle — an unentangled product state.

Mystery circuit: H on both qubits then CNOTTwo-qubit circuit: H on both wires, then CNOT q0 to q1. Output is |+⟩|+⟩ — an unentangled product state.|0⟩|0⟩HH|+⟩|+⟩CNOT redundant here: the uniform superposition is invariant under the permutation.
Applying $H$ to both qubits and then CNOT gives the same state as just applying the two $H$s. The circuit identity $\text{CNOT} \cdot (H \otimes H) |00\rangle = (H \otimes H)|00\rangle$ is specific to the $|00\rangle$ input; for other inputs, the CNOT matters.

Qiskit one-liner: qc.h(0); qc.h(1); qc.cx(0, 1); print(Statevector(qc)).

Problem 6: Build SWAP from 3 CNOTs

Given: two qubits in arbitrary states |a\rangle and |b\rangle (with a, b \in \{0, 1\} for the computational-basis check).

Target: a circuit that swaps the qubits — output state is |b\rangle \otimes |a\rangle.

Hint: three CNOTs with alternating control-target directions do the job.

Step 1. Apply CNOT with qubit 0 as control and qubit 1 as target. State |a\rangle|b\rangle \mapsto |a\rangle|a \oplus b\rangle, where \oplus is XOR.

Step 2. Apply CNOT with qubit 1 as control and qubit 0 as target. State |a\rangle|a\oplus b\rangle \mapsto |a \oplus (a \oplus b)\rangle |a \oplus b\rangle = |b\rangle |a \oplus b\rangle.

Why a \oplus (a \oplus b) = b: XOR is associative and a \oplus a = 0, so a \oplus a \oplus b = 0 \oplus b = b. The XOR trick for swapping bits without a temporary variable is a classical programming chestnut; CNOT implements it quantumly, linearly, on the whole computational-basis superposition.

Step 3. Apply CNOT with qubit 0 as control and qubit 1 as target. State |b\rangle|a \oplus b\rangle \mapsto |b\rangle |b \oplus (a \oplus b)\rangle = |b\rangle|a\rangle.

Result. Three CNOTs — alternating 0→1, 1→0, 0→1 — implement SWAP. Verify by computational-basis enumeration:

  • |00\rangle \mapsto |00\rangle (unchanged)
  • |01\rangle \mapsto |10\rangle (swapped)
  • |10\rangle \mapsto |01\rangle (swapped)
  • |11\rangle \mapsto |11\rangle (unchanged)

All four basis states map to the swapped version. By linearity, the same holds for every superposition input.

SWAP from 3 CNOTsTwo-qubit circuit with three CNOTs: 0 to 1, 1 to 0, 0 to 1. Equivalent to a SWAP gate.|a⟩|b⟩|b⟩|a⟩CNOT(0→1), then CNOT(1→0), then CNOT(0→1) — the quantum XOR swap.
Three alternating CNOTs implement a SWAP. The construction mirrors the classical "swap two bits without a temp variable using XOR" trick; the CNOT is the quantum XOR.

Qiskit one-liner: qc.cx(0, 1); qc.cx(1, 0); qc.cx(0, 1) — three CNOTs. Qiskit also has a native qc.swap(0, 1) that compiles to the same three CNOTs on hardware that only supports CNOTs.

Problem 7: Build controlled-$Z$ from CNOT and two Hadamards

Given: access to CNOT and single-qubit Hadamards.

Target: a controlled-Z gate, which applies a Z to qubit 1 iff qubit 0 is |1\rangle. On basis states:

  • |00\rangle \mapsto |00\rangle
  • |01\rangle \mapsto |01\rangle
  • |10\rangle \mapsto |10\rangle
  • |11\rangle \mapsto -|11\rangle

Hint: use the single-qubit identity HXH = Z (proved in Single-Qubit Practice, Problem 7). Sandwich the CNOT's target between two Hs.

Step 1. The identity HXH = Z says: conjugating X by H produces Z. If you replace the target's X (inside a CNOT) with HZH, the whole controlled-X becomes a controlled-Z.

Step 2. The construction:

\text{CZ} = (I \otimes H) \cdot \text{CNOT} \cdot (I \otimes H).

Verify on |11\rangle:

  • (I \otimes H)|11\rangle = |1\rangle \otimes H|1\rangle = |1\rangle \otimes \tfrac{1}{\sqrt 2}(|0\rangle - |1\rangle) = \tfrac{1}{\sqrt 2}(|10\rangle - |11\rangle).
  • CNOT flips qubit 1 iff qubit 0 = 1: \tfrac{1}{\sqrt 2}(|10\rangle - |11\rangle) \mapsto \tfrac{1}{\sqrt 2}(|11\rangle - |10\rangle).
  • (I \otimes H) on the result: H|1\rangle = \tfrac{1}{\sqrt 2}(|0\rangle - |1\rangle), H|0\rangle = \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle). So \tfrac{1}{\sqrt 2}(|1\rangle \otimes H|1\rangle - |1\rangle \otimes H|0\rangle) = \tfrac{1}{2}|1\rangle \otimes [(|0\rangle - |1\rangle) - (|0\rangle + |1\rangle)] = \tfrac{1}{2}|1\rangle \otimes (-2|1\rangle) = -|11\rangle. \checkmark

Why HZH = X and not the other way round: both directions work — HXH = Z and HZH = X, since H is self-inverse (H^2 = I). The version you use depends on what you already have. You have CNOT (which is controlled-X); sandwiching the target's X with Hs converts the X into Z, giving CZ.

Step 3. Sanity-check the remaining basis states:

  • |00\rangle: qubit 1 is already |0\rangle, the two Hs and the CNOT leave the state unchanged.
  • |01\rangle: after first H, state becomes \tfrac{1}{\sqrt 2}|0\rangle(|0\rangle - |1\rangle); CNOT (control=|0\rangle) does nothing; second H undoes the first. Net: |01\rangle.
  • |10\rangle: after first H, \tfrac{1}{\sqrt 2}|1\rangle(|0\rangle + |1\rangle); CNOT flips target based on control: \tfrac{1}{\sqrt 2}|1\rangle(|1\rangle + |0\rangle) — same thing, order of basis vectors only. Second H: |10\rangle back. Net: |10\rangle.
  • |11\rangle \mapsto -|11\rangle as computed above.

All four match the CZ truth table. The construction works.

Result. \text{CZ} = (I \otimes H) \cdot \text{CNOT} \cdot (I \otimes H) — a CNOT sandwiched between two Hadamards on the target wire.

Controlled-Z from CNOT and HTwo-qubit circuit: H on q1, then CNOT q0 to q1, then H on q1. Equivalent to CZ.q₀q₁HH≡ CZH on the target, CNOT, H on the target — a controlled-Z.
The CZ-from-CNOT-and-H construction. Hardware that offers only a CNOT as its native entangling gate uses this identity to realise any controlled-Pauli — and more generally, to conjugate CNOTs into other controlled-rotations.

Qiskit one-liner: qc.h(1); qc.cx(0, 1); qc.h(1) — three lines that implement qc.cz(0, 1).

Problem 8: Design a circuit around an oracle (Deutsch preview)

Given: an oracle U_f — a black-box two-qubit gate that implements a one-bit Boolean function f : \{0, 1\} \to \{0, 1\} as U_f |x\rangle|y\rangle = |x\rangle|y \oplus f(x)\rangle. You do not know what f is, but you have access to one use of U_f. You are told f is either constant (both f(0) and f(1) give the same bit) or balanced (they give different bits).

Target: decide, in a single use of the oracle, whether f is constant or balanced. (This is the simplest instance of Deutsch's algorithm.)

Hint: classically, you would need two queries — evaluate f(0) and f(1) separately. A quantum circuit can do it in one query, by exploiting superposition on the input register and phase kickback from the ancilla.

Step 1. Prepare two qubits. Qubit 0 (the input to f): |0\rangle. Qubit 1 (an ancilla): |1\rangle.

Step 2. Apply H to qubit 0 and H to qubit 1. The state becomes

\tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle) \otimes \tfrac{1}{\sqrt 2}(|0\rangle - |1\rangle) = \tfrac{1}{2}(|00\rangle - |01\rangle + |10\rangle - |11\rangle).

Step 3. Apply the oracle U_f. Compute term by term:

  • U_f|00\rangle = |0\rangle|0 \oplus f(0)\rangle = |0\rangle|f(0)\rangle.
  • U_f|01\rangle = |0\rangle|1 \oplus f(0)\rangle = |0\rangle|\overline{f(0)}\rangle.

So U_f (|00\rangle - |01\rangle) = |0\rangle(|f(0)\rangle - |\overline{f(0)}\rangle) = (-1)^{f(0)}|0\rangle(|0\rangle - |1\rangle).

Why the (-1)^{f(0)} factor: if f(0) = 0, |f(0)\rangle - |\overline{f(0)}\rangle = |0\rangle - |1\rangle. If f(0) = 1, it equals |1\rangle - |0\rangle = -(|0\rangle - |1\rangle). Either way, the result is (-1)^{f(0)}(|0\rangle - |1\rangle). The oracle's effect on the input qubit is multiplication by a phase — this is called phase kickback.

Similarly, U_f(|10\rangle - |11\rangle) = (-1)^{f(1)}|1\rangle(|0\rangle - |1\rangle).

The full state after U_f is \tfrac{1}{2}[(-1)^{f(0)}|0\rangle + (-1)^{f(1)}|1\rangle] \otimes (|0\rangle - |1\rangle).

Step 4. The ancilla has factored out and is now in state \tfrac{1}{\sqrt 2}(|0\rangle - |1\rangle) = H|1\rangle — the same as its initial value. Apply H to qubit 0 and measure it:

  • If f is constant, (-1)^{f(0)} = (-1)^{f(1)}, so the factor [(-1)^{f(0)}|0\rangle + (-1)^{f(1)}|1\rangle] is \pm (|0\rangle + |1\rangle), which Hadamards to \pm|0\rangle. Measurement gives 0.
  • If f is balanced, (-1)^{f(0)} = -(-1)^{f(1)}, so the factor is \pm(|0\rangle - |1\rangle), which Hadamards to \pm|1\rangle. Measurement gives 1.

Step 5. Read the measurement outcome. 0 \Rightarrow constant; 1 \Rightarrow balanced. One oracle call, one measurement, one deterministic answer.

Result. Deutsch's algorithm uses phase kickback to convert the classical property of f (constant vs balanced) into a quantum amplitude pattern on qubit 0, readable with a single measurement. This is the prototype of every quantum algorithm that achieves a provable speedup over classical — the speedup comes from interference between oracle branches, not from any mythical parallelism.

Deutsch's algorithm circuitA two-qubit circuit. Top wire q0 starts |0⟩ and ends with a measurement. Bottom wire q1 starts |1⟩. Gates in order: H on both, then an oracle Uf box spanning both wires, then H on q0 only, then measure q0.|0⟩|1⟩HHUforacleH0 = constant, 1 = balancedOne oracle call → deterministic answer via phase kickback and interference.
Deutsch's algorithm. Two Hadamards prepare a superposition input; the oracle applies phase kickback based on $f$; a final Hadamard translates the phase pattern into a measurement outcome. One oracle call, one answer.

Qiskit one-liner: qc.x(1); qc.h(0); qc.h(1); qc.append(Uf, [0, 1]); qc.h(0); qc.measure(0, 0).

Self-test: five problems

Now work these without looking at the solutions above. Each is solvable with the tools covered so far. Verify with Qiskit if you want (pip install qiskit and a Statevector print call is enough).

  1. Build the Bell state |\Psi^-\rangle from |00\rangle using the fewest possible gates. (Hint: combine tricks from Problems 2 and 3.)
  2. Build a three-qubit W state |W\rangle = \tfrac{1}{\sqrt 3}(|100\rangle + |010\rangle + |001\rangle) from |000\rangle. (This is genuinely harder than GHZ — you will need controlled rotations with non-right-angle parameters, or a clever reshape from a two-qubit state.)
  3. Given a three-qubit state |\psi\rangle, build a circuit that swaps qubits 0 and 2 (leaving qubit 1 alone). Use only CNOTs. (Hint: can you use two pairwise SWAPs?)
  4. Design a two-qubit circuit that, starting from |00\rangle, outputs |0\rangle on qubit 0 and \tfrac{1}{\sqrt 2}(|0\rangle + |1\rangle) on qubit 1. (Two different solutions exist — one with only Hadamards, and one with CNOT + H.)
  5. Trace through: starting from |+\rangle|+\rangle, apply CZ, then H to qubit 0, and finally measure qubit 0. What is the probability of measuring 0? What is the post-measurement state of qubit 1?

Summary — the multi-qubit gate reference

Multi-qubit gate and state referenceA reference table listing the core multi-qubit gates, the states they commonly produce, and the canonical circuit to build each. Entries: CNOT, CZ, SWAP, Toffoli, Bell states, GHZ state, W state, product state.Multi-qubit reference — states and the circuits that make themStateCircuit from |00...0⟩Gate count|Φ⁺⟩ = (|00⟩ + |11⟩)/√2H(q₀); CNOT(q₀→q₁)2|Φ⁻⟩ = (|00⟩ − |11⟩)/√2X(q₀); H(q₀); CNOT(q₀→q₁)3|Ψ⁺⟩ = (|01⟩ + |10⟩)/√2H(q₀); CNOT(q₀→q₁); X(q₁)3|Ψ⁻⟩ = (|01⟩ − |10⟩)/√2X(q₀); H(q₀); CNOT(q₀→q₁); X(q₁)4|GHZ⟩ = (|000⟩ + |111⟩)/√2H(q₀); CNOT(q₀→q₁); CNOT(q₀→q₂)3CZ = diag(1,1,1,−1)H(q₁); CNOT(q₀→q₁); H(q₁)3SWAP(q₀, q₁)CNOT(q₀→q₁); CNOT(q₁→q₀); CNOT(q₀→q₁)3|+⟩|+⟩ = uniform superpositionH(q₀); H(q₁)2Memorise these. Every two- and three-qubit algorithm starts by recognising one of these patterns.
Quick-reference table of multi-qubit states and the circuits that construct them from $|00\ldots 0\rangle$. Keep this by your notebook — half of every algorithm you read on arXiv starts with a pattern from this table.

Common confusions

Going deeper

If you can solve the eight worked problems and take an honest shot at the five self-tests, you have the multi-qubit toolkit in your hands. The sections below extend into Qiskit-based verification, multi-qubit state visualisation, and previews of the full quantum algorithms built from these building blocks.

Verifying problems in Qiskit

Qiskit is IBM's open-source quantum computing SDK, installable in one line (pip install qiskit qiskit-aer). Every problem in this article has a Qiskit verification of at most four lines:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
print(Statevector(qc))   # Expect: [1/√2, 0, 0, 1/√2] for |Phi+⟩

Swap in whichever circuit you want to verify. The Statevector class returns the full quantum state without collapsing it — a simulator luxury that real hardware cannot provide (real qubits give you measurement outcomes only).

For Indian students, IBM Quantum Platform (at quantum.ibm.com) offers free access to real superconducting quantum hardware. Account creation is free; the monthly allocation includes enough compute time to run every circuit in this article on a real chip in Yorktown Heights or Ehningen. Running a Bell-state preparation on real hardware and comparing the measurement statistics (which will be slightly off from 50/50 due to noise) to your simulator result is one of the most instructive single hours you can spend in quantum computing.

Multi-qubit state-vector visualisation with qsphere

The Bloch sphere does not extend to two or more qubits (four complex amplitudes do not fit on a 3D ball). Qiskit's qsphere visualisation plots each basis state as a point on a sphere, with the radial distance encoding the amplitude magnitude and the point's colour encoding the phase:

from qiskit.visualization import plot_state_qsphere
plot_state_qsphere(Statevector(qc))

For GHZ state: you see two bright dots at |000\rangle (north pole) and |111\rangle (south pole) — the two amplitudes that are nonzero — and six dim dots for the six basis states with amplitude zero. For W state: three dots at equal latitude on the "one-excitation" ring — the three basis states |100\rangle, |010\rangle, |001\rangle — each with amplitude 1/\sqrt 3. The structural difference between GHZ and W is visible in a single qsphere plot, which is exactly what a good visualisation should do.

Previews — teleportation and superdense coding

Both of these protocols are two-qubit algorithms built from the patterns above.

Quantum teleportation uses a Bell pair and a Bell measurement. Alice has unknown |\psi\rangle on qubit 0; Alice and Bob share |\Phi^+\rangle on qubits 1 and 2 (Alice holds qubit 1; Bob holds qubit 2). Alice applies CNOT(q_0 \to q_1), then H on q_0, then measures q_0 and q_1. The two classical bits tell Bob which of four Pauli corrections (I, X, Z, XZ) to apply to qubit 2; the result is that qubit 2 ends up in state |\psi\rangle. See classical-control for the full diagram.

Superdense coding runs teleportation in reverse — Alice and Bob share a Bell pair, and Alice encodes 2 classical bits into Alice's half by applying one of I, X, Z, XZ, then sends her qubit to Bob who does a Bell measurement to recover the 2 bits. It shows that 1 qubit can communicate 2 classical bits, given shared entanglement.

Both protocols use every single gate and state in Problems 1 through 7 above. Once you are fluent with the problems in this article, the protocols take about one page of working each.

Compiling to hardware-native gates

Real quantum chips do not run CNOTs directly — they run native gates specific to the hardware. Superconducting chips typically expose R_z, \sqrt{X}, and a two-qubit entangling gate like \text{ECR} or \text{CZ}. Qiskit's compiler (the transpile function) takes your circuit at the logical gate level (CNOTs, Hadamards) and rewrites it at the hardware gate level — which can dramatically change gate counts and depths.

A CNOT on an IBM Heron chip typically compiles to one ECR gate plus a handful of single-qubit rotations — a total of maybe 6 operations. A SWAP, being 3 CNOTs, compiles to around 18 operations. Every CNOT you can eliminate (by clever circuit design) saves real coherence. This is why circuit-identity tricks like Problem 7 matter: the (I \otimes H)\text{CNOT}(I \otimes H) = \text{CZ} identity saves gates when the native gate set contains CZ and not CNOT.

Extending to arbitrary oracle-based algorithms

Deutsch's algorithm (Problem 8) uses phase kickback from a 1-bit oracle. Real algorithms use oracles over many qubits — Deutsch-Jozsa works with n-bit oracles; Simon's algorithm extracts hidden structure from a more general black box; Grover's algorithm builds a diffusion operator around the oracle; Shor's algorithm embeds modular arithmetic into a quantum Fourier transform that feeds on the oracle's output. In every case, the three-move pattern is the same: put the input register into a uniform superposition with Hadamards, query the oracle once, apply interference-inducing gates, measure. The problems in this article are the opening moves of every one of these algorithms.

Where this leads next

References

  1. Qiskit Textbook, Multi-qubit gates and entanglement — interactive walk-throughs of Bell states, CNOT, Toffoli, and the identities used here.
  2. John Preskill, Lecture Notes on Quantum Computation, Chapters 4–5 — theory.caltech.edu/~preskill/ph229.
  3. Nielsen and Chuang, Quantum Computation and Quantum Information — §4.2–4.3 on multi-qubit gates and circuit identities — Cambridge University Press.
  4. Wikipedia, Quantum circuit — standard diagram conventions.
  5. IBM Quantum Learning, Introduction to Quantum Computing — free self-paced course covering the same circuits with hands-on Qiskit notebooks.
  6. Barenco et al., Elementary gates for quantum computation (1995) — arXiv:quant-ph/9503016 — the foundational decomposition paper showing every multi-qubit gate is built from single-qubit rotations and CNOTs.