DeepPractise
DeepPractise

SWAP Gate

Track: Quantum Gates & Circuits · Difficulty: Beginner · Est: 12 min

SWAP Gate

Overview

CNOT and CZ introduced conditional, entangling operations. The SWAP gate introduces a different capability:

  • it exchanges the states of two qubits.

This might sound simple, but it matters for multi-qubit reasoning because:

  • it lets you reorder which logical qubit is “in which place” in a multi-qubit state,
  • it helps manage where interactions happen when multi-qubit gates are only available between certain pairs.

We will keep this discussion general and conceptual—no circuit model yet.

Intuition

A two-qubit state can be written as a sum of basis states:

ψ=α00+β01+γ10+δ11.|\psi\rangle = \alpha|00\rangle + \beta|01\rangle + \gamma|10\rangle + \delta|11\rangle.

The symbols in ab|ab\rangle have an order: “first qubit” then “second qubit.” SWAP simply exchanges those roles.

At the level of basis states, it’s exactly what the name says:

  • 01|01\rangle becomes 10|10\rangle.
  • 10|10\rangle becomes 01|01\rangle.
  • 00|00\rangle and 11|11\rangle stay the same (because swapping identical bits changes nothing).

Why is SWAP needed “physically,” in a non-hardware-specific way?

In real implementations, multi-qubit interactions are typically not equally available between every pair of qubits. Even if we avoid device details, it’s realistic to assume:

  • some pairs can interact directly,
  • other pairs cannot.

SWAP is the abstract way to say:

  • “move the quantum information so the right pair can interact.”

This leads to the idea of logical vs physical location:

  • A logical qubit is “the qubit role” in your computation (the information you track).
  • A physical position is “where that role currently sits” among available qubits.

SWAP changes the mapping between logical roles and positions.

Formal Description

Action on computational basis states

SWAP is defined by

SWAP00=00,\text{SWAP}|00\rangle = |00\rangle, SWAP01=10,\text{SWAP}|01\rangle = |10\rangle, SWAP10=01,\text{SWAP}|10\rangle = |01\rangle, SWAP11=11.\text{SWAP}|11\rangle = |11\rangle.

What happens to amplitudes

Apply the same idea to a general state:

ψ=α00+β01+γ10+δ11.|\psi\rangle = \alpha|00\rangle + \beta|01\rangle + \gamma|10\rangle + \delta|11\rangle.

After SWAP:

SWAPψ=α00+β10+γ01+δ11.\text{SWAP}|\psi\rangle = \alpha|00\rangle + \beta|10\rangle + \gamma|01\rangle + \delta|11\rangle.

So:

  • amplitudes attached to 01|01\rangle and 10|10\rangle are exchanged.

A 4×4 matrix representation exists, but the basis mapping above is the most intuitive definition.

Worked Example

Consider the product state

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

Apply SWAP:

  • 0000|00\rangle \mapsto |00\rangle
  • 0110|01\rangle \mapsto |10\rangle

So

SWAP(0+)=12(00+10)=+0.\text{SWAP}(|0\rangle\otimes|+\rangle) = \tfrac{1}{\sqrt{2}}(|00\rangle + |10\rangle) = |+\rangle\otimes|0\rangle.

Interpretation:

  • SWAP moved the “+|+\rangle information” from the second qubit into the first.
  • Nothing mystical happened—just an exchange of roles.

Turtle Tip

Turtle Tip

If you can remember one fact: SWAP exchanges 01|01\rangle and 10|10\rangle. Everything else follows by linearity.

Common Pitfalls

Common Pitfalls
  • Don’t confuse SWAP with “copying.” SWAP does not duplicate information; it exchanges it.
  • Don’t assume qubit order is irrelevant. In multi-qubit states, which qubit is “first” matters; SWAP is how you intentionally change that ordering.

Quick Check

Quick Check
  1. What does SWAP do to 01|01\rangle?
  2. If you apply SWAP twice, what happens?

What’s Next

We’ve seen:

  • one-control gates (CNOT, CZ),
  • and a two-qubit reordering gate (SWAP).

Next we add a second control: the Toffoli (CCNOT) gate. It connects naturally to classical logic while still fitting cleanly into unitary, coherent multi-qubit evolution.