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:
The symbols in 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:
- becomes .
- becomes .
- and 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
What happens to amplitudes
Apply the same idea to a general state:
After SWAP:
So:
- amplitudes attached to and are exchanged.
A 4×4 matrix representation exists, but the basis mapping above is the most intuitive definition.
Worked Example
Consider the product state
Apply SWAP:
So
Interpretation:
- SWAP moved the “ information” from the second qubit into the first.
- Nothing mystical happened—just an exchange of roles.
Turtle Tip
If you can remember one fact: SWAP exchanges and . Everything else follows by linearity.
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
- What does SWAP do to ?
- 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.
