|q⟩ Bad Qubits

intermediate · Programming · Quantum Walks

Walk on a Line

A quantum walk is the quantum analogue of a classical random walk. Where a classical walker flips a coin to decide left or right, a quantum walker applies a unitary to its coin register and then performs a coherent conditional shift — keeping the superposition intact so that both directions evolve in parallel and their amplitudes interfere.

The classical picture

Start a classical random walker at position x=0x = 0. At each step flip a fair coin: heads, move to x1x-1; tails, move to x+1x+1. After tt steps the position probability distribution is a binomial centred at 0 with standard deviation σcl=t\sigma_{\text{cl}} = \sqrt{t}. The walk diffuses slowly.

The quantum walk on a line

The Hilbert space is the tensor product of a coin register and a position register:

ψHcoinHpos.|\psi\rangle \in \mathcal{H}_{\text{coin}} \otimes \mathcal{H}_{\text{pos}}.

A single step consists of two operations applied in sequence.

Coin operator CC: a unitary on the coin register alone. The standard choice is the Hadamard:

H0=12(0+1),H1=12(01).H|0\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle), \qquad H|1\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle - |1\rangle).

Shift operator SS: moves the walker left when the coin reads 0|0\rangle and right when it reads 1|1\rangle:

S=x(00x1x+11x+1x).S = \sum_{x} \bigl(|0\rangle\langle 0| \otimes |x-1\rangle\langle x| + |1\rangle\langle 1| \otimes |x+1\rangle\langle x|\bigr).

One full step is U=S(CIpos)U = S(C \otimes I_{\text{pos}}).

Interference leads to ballistic spreading

Because the walker stays in superposition, the amplitudes for different positions can add constructively or destructively. Starting with coin 0|0\rangle at position x=0x = 0, the probability distribution after tt steps has a characteristic two-peaked shape with tails near ±t/2\pm t/\sqrt{2}. The standard deviation grows as

σqut2,\sigma_{\text{qu}} \approx \frac{t}{\sqrt{2}},

which is linear in tt rather than t\sqrt{t}. This quadratic speed-up over classical diffusion is the reason quantum walks appear as subroutines in several quantum algorithms (element distinctness, graph search, NAND-formula evaluation).

Encoding for a small circuit

To build an exact circuit we encode a finite segment of the line. Use a 2-qubit position register (q1q2q_1 q_2, with q1q_1 as the most significant bit) for positions {0,1,2,3}\{0, 1, 2, 3\}, and a single coin qubit q0q_0. Three qubits in total.

Starting at the centre position 1=011 = |01\rangle with coin 0|0\rangle, one step proceeds:

  1. Coin toss: HH on q0q_0.

  2. Conditional decrement (move left when coin =0= |0\rangle): invert q0q_0, apply the controlled-decrement circuit CX(q0,q2);CCX(q0,q2,q1)\text{CX}(q_0, q_2);\, \text{CCX}(q_0, q_2, q_1), then invert q0q_0 again. The binary borrow-ripple decrement on q1q2q_1 q_2 triggers only when q0=1q_0 = 1 after the flip, i.e., originally q0=0q_0 = 0. Note the order: CX before CCX (the LSB is flipped first so that the carry check sees the updated LSB, implementing 1-1 rather than +1+1).

  3. Conditional increment (move right when coin =1= |1\rangle): apply CCX(q0,q2,q1);CX(q0,q2)\text{CCX}(q_0, q_2, q_1);\, \text{CX}(q_0, q_2) directly (no flips needed).

After the coin toss the state is 12(0+1)01\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle)|01\rangle. The decrement takes the 0|0\rangle branch from position 01|01\rangle to 00|00\rangle, and the increment takes the 1|1\rangle branch from 01|01\rangle to 10|10\rangle. The final state before measurement is

12(000+110).\frac{1}{\sqrt{2}}\bigl(|0\rangle|00\rangle + |1\rangle|10\rangle\bigr).

Measuring all three qubits yields bitstrings 000 and 110 with equal probability 12\tfrac{1}{2} — the walker has spread from the centre to positions 0 and 2.

Try it

Complete the one-step walk circuit. The grader checks the output distribution — you should see equal weight on the two displaced positions.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.