Back to Learn

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.

A coin flipped twice is still 50/50. A qubit sent through H twice comes back to |0⟩ every time: the two routes into |1⟩ have amplitudes +½ and −½ and cancel, while the routes into |0⟩ add up to 1.

Worked example: H twice returns |0⟩

Apply H to |+⟩ one basis state at a time, then collect matching terms.

H(∣0⟩+∣1⟩2)=12(H∣0⟩+H∣1⟩)H\left(\frac{|0\rangle+|1\rangle}{\sqrt{2}}\right)=\frac{1}{\sqrt{2}}\left(H|0\rangle+H|1\rangle\right)
=12(∣0⟩+∣1⟩)+12(∣0⟩−∣1⟩)=\frac{1}{2}\left(|0\rangle+|1\rangle\right)+\frac{1}{2}\left(|0\rangle-|1\rangle\right)
=(12+12)⏟1∣0⟩+(12−12)⏟0∣1⟩=∣0⟩=\underbrace{\left(\tfrac12+\tfrac12\right)}_{1}|0\rangle+\underbrace{\left(\tfrac12-\tfrac12\right)}_{0}|1\rangle=|0\rangle
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ⁿ.

Applying H to every qubit of |0…0⟩ spreads the probability evenly over all basis states. Each extra qubit doubles their number: 2, 4, 8, … 2ⁿ.

Worked example: two qubits

(H⊗H)∣00⟩=(∣0⟩+∣1⟩2)⊗(∣0⟩+∣1⟩2)=∣00⟩+∣01⟩+∣10⟩+∣11⟩2\begin{aligned}(H\otimes H)|00\rangle&=\left(\frac{|0\rangle+|1\rangle}{\sqrt{2}}\right)\otimes\left(\frac{|0\rangle+|1\rangle}{\sqrt{2}}\right)\\[6pt]&=\frac{|00\rangle+|01\rangle+|10\rangle+|11\rangle}{2}\end{aligned}
Each probability=∣12∣2=14=25%4⋅14=1\text{Each probability}=\left|\frac{1}{2}\right|^2=\frac{1}{4}=25\%\qquad 4\cdot\frac{1}{4}=1
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.

∣+⟩=∣0⟩+∣1⟩2∣−⟩=∣0⟩−∣1⟩2|+\rangle=\frac{|0\rangle+|1\rangle}{\sqrt{2}}\qquad |-\rangle=\frac{|0\rangle-|1\rangle}{\sqrt{2}}
P∣+⟩(0)=P∣+⟩(1)=P∣−⟩(0)=P∣−⟩(1)=12P_{|+\rangle}(0)=P_{|+\rangle}(1)=P_{|-\rangle}(0)=P_{|-\rangle}(1)=\frac{1}{2}
H∣+⟩=∣0⟩H∣−⟩=∣1⟩H|+\rangle=|0\rangle\qquad H|-\rangle=|1\rangle
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.