beginner · Programming · First Quantum Algorithms: Deutsch & Deutsch–Jozsa
Quantum Parallelism
A classical computer that wants to know f(0) and f(1) for some function f must call f twice.
Quantum mechanics offers a striking shortcut: by preparing the input in a superposition of every
possible value and calling f only once, both results are encoded in the output state simultaneously.
This is the phenomenon called quantum parallelism.
How it works
Set up two registers. The input register is a single qubit starting in ∣0⟩; the
output register is also a single qubit starting in ∣0⟩. Apply a Hadamard to the input:
H∣0⟩=21(∣0⟩+∣1⟩).
The combined state of both registers is now
21(∣0⟩+∣1⟩)⊗∣0⟩=21(∣00⟩+∣10⟩),
where the first index labels the input and the second labels the output (qubit 0 is the most
significant bit in this platform's convention).
A query oracleUf acts on the combined state according to
Uf∣x⟩∣y⟩=∣x⟩∣y⊕f(x)⟩,
where ⊕ is addition modulo 2. With y=0 this simplifies to Uf∣x⟩∣0⟩=∣x⟩∣f(x)⟩, so the output register simply stores f(x).
Applying Uf to the superposed state gives
Uf21(∣00⟩+∣10⟩)=21(∣0⟩∣f(0)⟩+∣1⟩∣f(1)⟩).
Both values f(0) and f(1) appear in the state at the same time — the oracle was called only once.
The f(x) = x oracle as a CNOT
For the function f(x)=x the oracle maps ∣x⟩∣0⟩→∣x⟩∣x⟩. That is
exactly the action of a CNOT gate with qubit 0 as control and qubit 1 as target:
CNOT:∣00⟩→∣00⟩,∣10⟩→∣11⟩.
After H on qubit 0 followed by CNOT, the state is
21(∣00⟩+∣11⟩),
a maximally entangled Bell state. The oracle has evaluated f on both inputs in one step.
Try it
Build the circuit that places the input register in superposition and then evaluates f(x)=x via a CNOT oracle. The grader checks the full state vector.
Run your code to see the quantum state.
After running, inspect the amplitudes: you should see 21≈0.707 on
∣00⟩ and ∣11⟩, and zero everywhere else.
Sign in on the full site to ask questions and join the discussion.