About Quantum Gates & Circuits
Quantum gates are unitary operators that transform qubit states. Just as classical logic gates (AND, OR, NOT) manipulate bits, quantum gates manipulate qubits — but with the full power of superposition and entanglement. Each gate corresponds to a unitary matrix U satisfying U†U = I, which guarantees that probabilities are preserved. A quantum circuit composes gates sequentially: the state vector |psi> is updated by matrix multiplication at each step. Single-qubit gates (H, X, Y, Z, S, T) act on individual qubits, while multi-qubit gates (CNOT, CZ, SWAP) create correlations between qubits, including entanglement. This visualization lets you build a circuit gate by gate, observe how the full 2^n-dimensional state vector evolves, and see measurement probabilities update in real time.
Complexity Analysis
- Time Complexity
- O(2^n * g)
- Space Complexity
- O(2^n)
- Difficulty
- intermediate
Key Concepts
Quantum Gates
Quantum gates are the building blocks of quantum computation. Each gate is a unitary transformation that acts on one or more qubits. Common single-qubit gates include Hadamard (H), Pauli-X (bit flip), Pauli-Z (phase flip), and rotation gates (Rx, Ry, Rz).
Unitary Matrices
Every quantum gate is represented by a unitary matrix U satisfying U†U = UU† = I. This ensures that the total probability of all measurement outcomes always sums to 1. Unitarity also means every quantum operation is reversible.
Circuit Model
The quantum circuit model represents computation as a sequence of gates applied to qubits, drawn as horizontal wires. Gates are applied left to right. The circuit model is the most common framework for designing quantum algorithms, analogous to logic circuits in classical computing.
Multi-Qubit Gates
Multi-qubit gates act on two or more qubits simultaneously. The CNOT (controlled-NOT) gate is the most important: it flips a target qubit only when the control qubit is |1>. CNOT is essential for creating entanglement and is, together with single-qubit gates, universal for quantum computation.
Common Pitfalls
Gate ordering matters
Unlike some classical operations, quantum gate order is critical. Applying H then Z produces a different result from Z then H, because matrix multiplication is not commutative. Always read circuits from left to right.
Global phase irrelevance
Two state vectors that differ only by a global phase factor e^{iγ} (e.g., |psi> and -|psi>) are physically indistinguishable. However, relative phase between amplitudes is observable and crucial for interference effects.
Measurement destroys superposition
Measuring a qubit collapses its state to |0> or |1> probabilistically. After measurement, the superposition is lost and the qubit is in a definite classical state. This is irreversible, unlike gate operations.