Quantum Computing 101
Superposition
Superposition means several basis states carry amplitude at once, and those amplitudes can reinforce or cancel each other.
In this lesson you will learn to
- Tell a superposition apart from a random classical bit.
- Use H to create equal superpositions on one or many qubits.
- Explain interference using the fact that applying H twice does nothing.
- Recognize relative phase in the states |+⟩ and |−⟩.
More Than a Coin Flip
A qubit is in superposition when more than one basis state has a nonzero amplitude. The state |+⟩ = (|0⟩ + |1⟩)/√2 is the classic example: measuring it gives 0 or 1, each half the time.
So far that sounds like a fair coin. The difference appears when you act on the state before measuring. A coin flipped twice is still random, but a qubit's amplitudes can add up or cancel out. This effect, interference, is the engine behind every quantum algorithm.
Worked example: H twice returns |0⟩
Apply H to |+⟩ one basis state at a time, then collect matching terms.
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(1)
qc.h(0)
qc.h(0)
print(Statevector.from_instruction(qc).probabilities_dict(decimals=3))
# {'0': 1.0}Hadamard Gates
The Hadamard gate H is the standard way to create a superposition. It maps |0⟩ to |+⟩ and |1⟩ to |−⟩ = (|0⟩ − |1⟩)/√2.
Applying H to every qubit of a register spreads the amplitude evenly over every basis state. With n qubits there are 2ⁿ basis states, so each gets amplitude 1/√(2ⁿ) and probability 1/2ⁿ.
Worked example: two qubits
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(2)
qc.h([0, 1])
print(Statevector.from_instruction(qc).probabilities_dict(decimals=3))
# {'00': 0.25, '01': 0.25, '10': 0.25, '11': 0.25}›Check yourself: You apply H to each of 5 qubits, starting from |00000⟩. How many basis states have nonzero amplitude, and what is the probability of each?
2⁵ = 32 basis states, each with amplitude 1/√32 and probability 1/32, about 3.1%.
Relative Phase
|+⟩ and |−⟩ give exactly the same measurement statistics: 50% each. The only difference is the minus sign on |1⟩, which is called a relative phase.
Relative phase is invisible to a direct measurement but not to the next gate. Applying H turns |+⟩ into |0⟩ and |−⟩ into |1⟩, so the hidden sign becomes a certain, measurable result.
Worked example: same odds, different futures
|+⟩ and |−⟩ measure identically, but one more H separates them completely.
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
plus = QuantumCircuit(1)
plus.h(0) # |+>
minus = QuantumCircuit(1)
minus.x(0)
minus.h(0) # |->
for name, qc in [("plus", plus), ("minus", minus)]:
print(name, Statevector.from_instruction(qc).probabilities_dict(decimals=3))
qc.h(0)
print(name, "after H", Statevector.from_instruction(qc).probabilities_dict(decimals=3))
# plus {'0': 0.5, '1': 0.5}
# plus after H {'0': 1.0}
# minus {'0': 0.5, '1': 0.5}
# minus after H {'1': 1.0}Key Takeaways
- A superposition gives amplitude to several basis states at once.
- Unlike a coin, amplitudes interfere: routes to the same outcome add, signs included.
- H on every qubit of |0…0⟩ spreads amplitude evenly over all 2ⁿ basis states.
- |+⟩ and |−⟩ have the same probabilities but different relative phase, and H reveals it.
What To Practice
Practice creating superpositions, predicting every amplitude, and steering phases.
- Signed Hadamard ChainEasy ★Mix |+⟩ and |−⟩ qubits and predict the sign of each of the 2ⁿ amplitudes.
- Wildcard SuperpositionEasy ★Prepare a uniform superposition over exactly the bitstrings a pattern allows.
- Fourier Phase RampEasy ★Build a superposition whose phases wind around evenly, using single-qubit gates only.
- Phase Kickback DialEasy ★Write a chosen relative phase onto a qubit through a controlled gate.