๐Ÿ”ฎ Before we begin โ€” the first quantum algorithm
Imagine a black box โ€” a function f(x) โ€” that takes a single bit (0 or 1) as input and gives a single bit as output. You don't know what's inside. You only know one of two things is true: either the function always gives the same output regardless of input (constant: f(0)=f(1)), or the function gives different outputs for different inputs (balanced: f(0)โ‰ f(1)).

Classically, to determine which kind it is, you must query the function twice โ€” once with input 0, once with input 1. There is no way around this.

In 1985, David Deutsch showed that a quantum computer can determine the answer with just one query. The algorithm puts the input into superposition, queries both 0 and 1 simultaneously, and uses interference to collapse directly to the answer. This was the first proof that quantum computers can solve a problem faster than any classical computer.
๐ŸŒ€ The philosophical significance
Deutsch's algorithm is almost useless practically โ€” the problem it solves is artificial. But historically it was everything. It proved that quantum computation is not just faster classical computation โ€” it is a fundamentally different model of computation. Every quantum algorithm since (Grover, Shor, QFT) builds on the same principle: superposition + interference = a single query answering what would take many classical queries.
๐Ÿ”ฎ Quantum Algorithms ยท Session 4 ยท Q10

Deutsch's Oracle

The algorithm that started it all. One quantum query does what two classical queries cannot avoid. Watch superposition and interference solve the problem in a single shot.

โ“ The Problem
๐Ÿ”ฎ The Oracle
โšก The Circuit
๐Ÿ“Š Deutsch-Jozsa
๐Ÿ† Badge
โ“

The question

Is f(x) constant (always same output) or balanced (different outputs)? Classical: 2 queries. Quantum: 1 query.

๐Ÿ”ฎ

The oracle

A black-box quantum gate Uf that encodes f(x) without revealing it. You can only query it โ€” not look inside.

โšก

The trick

H โ†’ Uf โ†’ H. Superposition queries both inputs at once. Interference makes the answer appear in the measurement.

๐Ÿ“Š

Deutsch-Jozsa

Generalises to n bits. Classical needs up to 2โฟโปยน+1 queries. Quantum still needs only 1. Exponential speedup.

๐Ÿ”ฎ
Wizzy ยท Quantum Guide
There are only 4 possible functions f:{0,1}โ†’{0,1}. Two are constant (always output 0, or always output 1). Two are balanced (output flips). Classically you must query the function twice to tell which kind it is. There's no shortcut โ€” the first query tells you nothing alone.
๐ŸŒ€ Why the first query isn't enough classically
If f(0)=0, the function could be "constant 0" or "balanced (outputs 0 for 0, 1 for 1)". You can't tell without also querying f(1). So classically you always need both queries. Deutsch's trick is to query f(0) AND f(1) simultaneously with one quantum operation.

Step 1 โ€” The 4 Possible Functions

โœ… Constant functions (2 total)
fโ‚ โ€” Constant 0: f(0)=0, f(1)=0
fโ‚‚ โ€” Constant 1: f(0)=1, f(1)=1
โš–๏ธ Balanced functions (2 total)
fโ‚ƒ โ€” Identity: f(0)=0, f(1)=1
fโ‚„ โ€” NOT: f(0)=1, f(1)=0
The classical challenge: You receive a mystery oracle โ€” one of these 4 functions. To determine if it's constant or balanced, you must call it with both inputs 0 and 1. That's always 2 queries. No classical algorithm can do it in 1.
Classical minimum queries
2 queries
Always โ€” no exception
๐Ÿ”ฎ
Wizzy ยท Quantum Guide
A quantum oracle Uf is a reversible gate that maps |xโŸฉ|yโŸฉ โ†’ |xโŸฉ|y โŠ• f(x)โŸฉ. It encodes the function in a phase-kickback-friendly way. Select an oracle below and see its truth table. The key: when we put |xโŸฉ in superposition and |yโŸฉ = |โ€“โŸฉ, the oracle's effect gets kicked back into the phase of |xโŸฉ โ€” and that's detectable with one measurement.
๐ŸŒ€ Phase kickback โ€” the magic ingredient
When the ancilla qubit is prepared as |โ€“โŸฉ = (|0โŸฉ-|1โŸฉ)/โˆš2, querying the oracle flips the phase of |xโŸฉ based on f(x). Constant f: no phase difference. Balanced f: opposite phases. This difference is detectable via interference โ€” without ever directly reading f(0) or f(1).

Step 2 โ€” Choose a Quantum Oracle

fโ‚ โ€” Constant 0

Always outputs 0. Never changes the ancilla qubit.

f(0)=0f(1)=0 CONSTANT
fโ‚‚ โ€” Constant 1

Always outputs 1. Flips ancilla qubit always.

f(0)=1f(1)=1 CONSTANT
fโ‚ƒ โ€” Identity (balanced)

Outputs what it receives. Ancilla flips iff x=1.

f(0)=0f(1)=1 BALANCED
fโ‚„ โ€” NOT (balanced)

Flips every input. Ancilla flips iff x=0.

f(0)=1f(1)=0 BALANCED
Select an oracle. The quantum algorithm will determine if it's constant or balanced โ€” using only 1 query.
๐Ÿ”ฎ
Wizzy ยท Quantum Guide
The full Deutsch circuit: prepare both qubits, apply H to both, query the oracle once, apply H to the first qubit, measure. Press each step to walk through the state evolution. The key moment is after the oracle โ€” the phase of qubit 0 encodes the answer through destructive interference.
๐ŸŒ€ How one query beats two
The oracle is called exactly once โ€” but it's called with qubit 0 in superposition (|0โŸฉ+|1โŸฉ)/โˆš2. This means it effectively evaluates f(0) and f(1) simultaneously. The ancilla qubit |โ€“โŸฉ converts the function evaluation into a phase flip โ€” and the final H gate on qubit 0 turns the phase difference into an observable amplitude difference.

Step 3 โ€” Deutsch's Algorithm

Oracle: none selected
Press Step to walk through the circuit. Each press advances one gate.
๐Ÿ”ฎ
Wizzy ยท Quantum Guide
Deutsch-Jozsa extends this to n-bit functions. For n=10, a classical computer needs up to 513 queries (2โน+1) to be certain. Quantum still needs exactly 1 query. The speedup grows exponentially with n. Drag the slider to see the comparison.
๐ŸŒ€ Exponential speedup from one circuit
The same H โ†’ Uf โ†’ H structure works for n qubits. Apply H to all n input qubits simultaneously, query the oracle once on n qubits in superposition, apply H to all n qubits, measure. One oracle call. Always. The classical algorithm's query count grows as 2โฟโปยน+1. Quantum stays at 1.

Step 4 โ€” Deutsch-Jozsa: n-bit Scaling

4
Classical worst case
9
2โฟโปยน + 1 queries
Quantum (always)
1
1 query โ€” always
With 4 bits: classical needs up to 9 queries, quantum needs 1
Real-world relevance: Deutsch-Jozsa itself is rarely used in practice โ€” the problem is contrived. But it demonstrated the principle that launched quantum algorithm theory. Grover (Q11) and Shor (Q12) use the same fundamental mechanism for genuinely useful problems.
๐Ÿ”ฎ
Wizzy ยท Quantum Guide
๐ŸŽŠ You've understood the first quantum algorithm ever devised! In 1985, Deutsch proved quantum computers are fundamentally different. Every quantum algorithm you'll learn โ€” Grover, Shor, QFT โ€” builds on this same foundation: superposition + phase kickback + interference = fewer queries.
๐Ÿง  What you actually learned today
  • The constant-vs-balanced problem: 4 possible functions, 2 query classical minimum, 1 query quantum solution.
  • Quantum oracles are reversible gates Uf that map |xโŸฉ|yโŸฉ โ†’ |xโŸฉ|yโŠ•f(x)โŸฉ โ€” they encode functions without revealing them directly.
  • Phase kickback: preparing the ancilla as |โ€“โŸฉ turns oracle queries into phase flips on the input qubit โ€” detectable by interference.
  • Deutsch's circuit: H โ†’ Uf โ†’ H gives the answer in one oracle query through superposition and interference.
  • Deutsch-Jozsa generalises to n bits: classical needs 2โฟโปยน+1 queries, quantum needs 1 โ€” exponential speedup from a single circuit.
๐Ÿ”ฎ

Oracle Master Badge!

You understood the algorithm that launched the quantum computing revolution!

๐Ÿ”ฎ WhizzStep Quantum Lab
This certifies that
Student Name
has mastered Deutsch's Oracle โ€” the first quantum algorithm
Oracle Master
Phase Kickback
Deutsch-Jozsa
๐Ÿ“– Quantum Vocabulary
Oracle NEW

A black-box quantum gate that encodes a function f without revealing its internals. You can only query it โ€” not inspect it. Crucial to quantum algorithms.

Like a locked vending machine โ€” you put in an input and get an output, but can't see the mechanism inside.
Phase kickback KEY

When the ancilla qubit is |โ€“โŸฉ, an oracle query flips the phase of the control qubit based on f(x). This converts function evaluation into a phase โ€” detectable by H gates.

Constant function

f(0) = f(1) โ€” same output regardless of input. Deutsch's algorithm outputs |0โŸฉ when measured.

Balanced function

f(0) โ‰  f(1) โ€” different output for each input. Deutsch's algorithm outputs |1โŸฉ when measured. Perfect correlation โ€” no ambiguity.

Query complexity NEW

The number of times you call an oracle to solve a problem. Quantum algorithms often achieve exponentially lower query complexity than classical ones.

Deutsch-Jozsa

The n-bit generalisation. 1 quantum query vs 2โฟโปยน+1 classical queries for n-bit constant-vs-balanced testing. The first exponential quantum speedup proof.

Key Concepts from Q10

Oracles

๐Ÿ”ฎ Black-box gates

Quantum algorithms are usually analysed in terms of oracle queries โ€” how many times must you call the black box? Reducing this count is the quantum advantage.

Phase kickback

โšก The core mechanism

Preparing the ancilla as |โ€“โŸฉ converts oracle function evaluation into phase manipulation โ€” and phases are manipulated by H gates into probabilities. This exact trick powers Grover and Shor.

Interference

๐ŸŒŠ The amplifier

Constant oracle: both paths have same phase โ†’ constructive interference โ†’ measure 0. Balanced oracle: opposite phases โ†’ destructive interference โ†’ measure 1. One query, definite answer.

Deutsch-Jozsa

๐Ÿ“Š Exponential gap

The n-bit version of Deutsch's algorithm gave the first proof of an exponential quantum speedup over classical computation. Historically crucial, even if the problem was contrived.