Quantum_Algorithms_Teachers Quantum vs. Classical: Exponential Advantage
1.
Quantum Algorithms
for theClassroom
Deutsch-Jozsa · Grover's Search · Real-World Impact · Puzzle Activities
Puzzle Games
Layman
Explained
Code Snippets
Real World
Impact
IBM Quantum Computing Workshop | Day 2 | 13 March 2025
🧩 PUZZLE WARM-UP— Teacher Activity
A mysterious machine takes a number and outputs 0 or 1.
🎰 CLUE 1
You test the machine with input 1 →
output: 0
You test with input 2 → output: 0
You test with input 3 → output: 0
❓ Is it BROKEN or WORKING?
🎲 CLUE 2
Input 1 → 0 Input 2 → 1
Input 3 → 0 Input 4 → 1
Input 5 → 0 Input 6 → 1
❓ Broken or Working?
How many tests needed?
🧠 CLUE 3
You have 1 BILLION possible inputs.
You have time for only 1 test.
Can you ever be 100% certain?
❓ What would a QUANTUM
computer do differently?
💡 Deutsch-Jozsa algorithm answers Clue 3 perfectly — with just ONE quantum query, for ANY number of inputs!
4.
Deutsch-Jozsa: The CookieFactory
🏭 The Story
You're a quality inspector at a cookie factory.
A mystery machine stamps each recipe PASS (0) or FAIL (1).
🔴 BROKEN machine
Always stamps the same
(all PASS or all FAIL)
🟢 WORKING machine
Exactly half PASS, half FAIL
(tests recipes properly!)
🎯 Your job: figure out WHICH type it is!
Classical vs Quantum
🐌 Classical Approach
Test recipe 1 → see result
Test recipe 2 → see result
...
Worst case: N/2 + 1 tests!
⚡ Quantum Approach
Put ALL recipes into superposition
Test them ALL simultaneously
Interference reveals the answer
ALWAYS just 1 test! ✅
For 1 BILLION recipes: classical = 500M tests · Quantum = 1 test
5.
D-J: Quantum Interference— The Magic Explained
The Deutsch-Jozsa Circuit
q0
q1
q2
anc X
H
H
H
H
①
H on all
Oracle
Uf
②
Oracle
H
H
H
③
H again
M
M
M
④
Measure
000
or
non-0
🎸 Sound Wave Analogy
Superposition
H gate asks ALL recipe numbers at once. Like
humming every frequency simultaneously.
Constant Oracle
All paths add up (constructive interference) →
Measures all 000s → verdict: CONSTANT
Balanced Oracle
Half paths cancel out (destructive interference) →
Measures non-zero → verdict: BALANCED
All-zeros → CONSTANT | Any non-zero →
BALANCED
6.
Deutsch-Jozsa: Circuit &Code
● deutsch_jozsa.py
from qiskit import QuantumCircuit
def build_balanced_dj(n):
# n input qubits + 1 ancilla
qc = QuantumCircuit(n+1, n)
# Ancilla → |1
① ⟩
qc.x(n)
# H on ALL qubits
②
qc.h(range(n+1))
# Balanced oracle (parity)
③
for i in range(n):
qc.cx(i, n)
# H again on inputs
④
qc.h(range(n))
qc.measure(range(n), range(n))
return qc
4 Steps of the Algorithm
①
Ancilla to |1⟩
The helper qubit needs to be |1 so the oracle can
⟩
'write' into quantum phases.
②
H on everything
Creates superposition of ALL inputs — we're testing
every recipe simultaneously!
③
Apply Oracle
CNOT gates encode the function into the quantum
state (balanced = CNOT per qubit).
④
H again + Measure
Interference collapses state. All-zeros = constant. Non-
zero = balanced.
Result: measure 000 → CONSTANT | non-000 → BALANCED
🧩 PUZZLE: TheHaystack Problem
🌾
A bag has 1,000,000 marbles. One is RED. The rest are white. You can only check one marble at
a time.
How many checks do you need to find the red marble? (Ask the class!)
🐢
Person A says:
On average: 500,000 checks
Classical sequential
search — O(N)
😱
Person B says:
Up to 1,000,000 checks
Classical worst case
(marble is last!)
⚡
Quantum says:
About 785 checks!
Grover's algorithm
O(√N) = √1,000,000
✅ 1,270× FASTER!
🎯 Grover's Key Insight: Don't search item by item — amplify the right answer's 'volume' until it SHOUTS!
9.
Grover's Algorithm: HowIt Works Step by Step
① Superpose
Apply H to ALL qubits.
Every item in the database
now has equal, tiny
probability.
Like shining a dim light on all
marbles at once.
qc.h(range(n))
② Oracle
Mark the target with a phase
flip (×–1). It's invisible to us,
but changes the quantum
state internally.
Like putting an invisible sticker
on the red marble.
# Phase flip target
qc.h(n-1)
qc.mcx([...], n-1)
qc.h(n-1)
③ Diffuse
Inversion about the average —
reflect all amplitudes around
the mean. Marked item grows
bigger; others shrink.
Like turning up the volume on
one frequency.
qc.h(range(n))
qc.x(range(n))
# multi-CZ
qc.x(range(n))
qc.h(range(n))
④ Repeat √N ×
Measure
Repeat Oracle+Diffuse exactly
π/4·√N times. Then measure
— target found with ~100%
probability!
for _ in range(
round(π/4 * √N)):
qc.compose(oracle)
qc.compose(diff)
qc.measure(...)
▶ ▶ ▶
10.
Grover's: Probability Growswith Each Iteration
🎯 Key Observations
Quantum probability OSCILLATES
It peaks then comes back down. Over-iterate =
overshoot!
Optimal at k = π/4 × √N
This is where ~100% probability is reached. The
'sweet spot'.
Classical is flat: 1/N per guess
No matter how many tries, each classical guess
is still just 1/N.
Timing is everything!
Stop at exactly the right iteration — like
catching a swing at peak height.
N=64
items
~100%
success rate
O(√N)
complexity
Proven
speedup
11.
Grover's Algorithm: Circuit& Key Code
● grover_search.py
# Optimal iterations = π/4 × √N
opt = round((π/4)*sqrt(N))
# Build circuit
qc = QuantumCircuit(n, n)
# Equal superposition
①
qc.h(range(n))
# Grover iterations
②
for _ in range(opt):
# Oracle marks target
qc.compose(oracle)
# Diffusion amplifies
qc.compose(diffusion)
# Measure
③
qc.measure(range(n), range(n))
# Run on simulator
result = sim.run(qc, shots=100)
# Target found ~100% of the time!
Grover Circuit Anatomy
q0
q1
H
H
Super
pose
Oracle
Uω
Mark
target
Diff.
Grover
Amplify
target
⟳ Repeat √N times
M
M
Measu
re
Queries Comparison
N = 4 items 2 queries avg 1 iteration 2×
N = 64 items 32 queries avg 6 iterations 5×
N = 1M items 500K queries 785 iterations
637
×
12.
Grover's Speedup: TheNumbers Scale Dramatically
N = 100
Classical: 50 queries → Quantum: 8
queries
6×
N = 10,000
Classical: 5,000 queries → Quantum: 79
queries
63×
N = 1,000,000
Classical: 500,000 queries → Quantum:
785 queries
637×
N = 2^40 items
Classical: 549B queries → Quantum:
826K queries
665K
×
The bigger the database, the larger the quantum advantage. For N = 2⁴⁰ items, Grover is 665,000× faster!
13.
Head-to-Head: Deutsch-Jozsa vsGrover's Search
🍪 Deutsch-Jozsa 🔍 Grover's Search
Problem Is f constant or balanced? Find 1 item in N items
Quantum advantage EXPONENTIAL (1 vs 2^n) QUADRATIC (√N vs N)
Classical queries Up to 2^(n-1)+1 Up to N queries
Quantum queries Always 1 🎯 ~π/4 × √N 🎯
Analogy
Cookie inspector
checks all recipes at once
Spotlight finds red marble
among millions instantly
Real-world app
Classifying huge datasets
without reading them all
Drug molecule search,
cryptography, AI optimization
✅ Both use SUPERPOSITION to check multiple states at once · Both use INTERFERENCE to reveal the answer
14.
Real-World Impact
How Deutsch-Jozsa& Grover's Change Everything
Pharma & Drug
Discovery
Cybersecurity AI & Machine Learning
Finance & Banking Materials Science Logistics & Supply Chain
15.
Real-World Impact: DrugDiscovery & Cybersecurity
💊 Drug Discovery (Grover's)
Finding the right molecular configuration is like finding a needle in a haystack of 10^40 possibilities.
🐌 Classical:
Classical supercomputers: test candidate molecules one
by one.
Simulating caffeine: 160-qubit problem — impossible
classically.
⚡ Quantum:
Grover's searches the molecular config space in √N steps.
A 1,000× speedup on identifying drug candidates for cancer,
Alzheimer's, and COVID variants.
GROVER
🔐 Cybersecurity (Grover's + D-J)
AES-256 encryption is only secure if no one can brute-force the key — 2^256 possibilities.
🐌 Classical:
Classical brute-force: 2^256 operations.
Would take longer than the age of the universe.
⚡ Quantum:
Grover's reduces AES-256 security to effectively AES-128.
D-J helps detect patterns in encrypted data without
decrypting it — 1 quantum query vs. trillions classically.
D-J
+
GROVER
🌍 Global quantum computing market projected to reach $450 billion by 2035
16.
Real-World Impact: AI· Finance · Materials · Logistics
🧠 Artificial Intelligence Grover's
🔍 Problem: Training AI requires searching massive parameter spaces.
⚡ Quantum: Grover's accelerates optimization of neural network
weights. Finding the best configuration in √N steps instead of N.
🏭 Google's quantum team showed ~100× speedup on certain ML training
tasks.
💰 Finance & Risk Analysis Grover's
🔍 Problem: Portfolio optimization: find the best portfolio from 2^500
possible combinations.
⚡ Quantum: Grover's searches the entire portfolio space in √(2^500) =
2^250 steps — making an impossible problem tractable.
🏭 JPMorgan, Goldman Sachs and IBM are actively piloting quantum
finance algorithms.
⚗️Materials Science D-J
🔍 Problem: Does this new material have the right properties? Classical
testing is exhaustive.
⚡ Quantum: D-J-style algorithms test whether a material's property
function is 'constant' (no useful property) or 'balanced' (has what we
need) — in ONE query.
🏭 Used for battery material discovery, superconductor design, and solar cell
optimization.
🚚 Logistics & Supply Chain Grover's
🔍 Problem: Amazon has 120 warehouses. Find the optimal delivery
route among N! combinations.
⚡ Quantum: Grover's searches the route space in √(N!) steps. For 20
stops: classical = 2.4 quintillion paths, quantum = ~1.5 billion.
🏭 Volkswagen, DHL, and Airbus are using quantum algorithms for routing
optimization.
17.
🏆 Quiz Time!— Test Your Understanding
Q1: A function with 1 million inputs is either constant or balanced.
How many queries does Deutsch-Jozsa need?
A) 500,001 B) 1,000
✅ C) 1 — always! D) It depends
Q2: Grover's searches 1 billion items. Classical average = 500 million.
How many does Grover's need?
A) 500 million ✅ B) 31,623 (≈ √1B)
C) 100 D) 1
Q3: What creates the 'magic' in both algorithms?
A) Faster processors B) More RAM
✅ C) Quantum
interference
D) Better sorting
18.
Key Takeaways —What to Remember
Deutsch-Jozsa
1 quantum query answers a question that classically
needs up to 2^(n-1)+1 queries. Uses interference to
'hear' whether a function is constant or balanced.
Grover's Search
√N quantum queries find a needle in N haystacks.
Quadratic speedup. The bigger the dataset, the more
dramatic the advantage.
Quantum Superpower
Both algorithms exploit SUPERPOSITION (check all at
once) and INTERFERENCE (amplify right answers,
cancel wrong ones).
Real-World Ready
Pharma, finance, cybersecurity, AI, and logistics are
all investing in quantum algorithms NOW. These
aren't theoretical — they're being built.
⚛️'I think I can safely say nobody understands quantum mechanics...' but NOW your students can BUILD with it! — inspired by Feynman
19.
Your Students AreNow Quantum-Ready!
Deutsch-Jozsa · Grover's Search · Real-World Impact
📚 Resources for Teachers & Students:
IBM Quantum Learning
learning.quantum.ibm.com
Qiskit Textbook
qiskit.org/learn
Day 2 Notebook
Day2_Quantum_Workshop_v2.ipynb
IBM Quantum Platform
quantum.ibm.com
IBM Quantum Workshop · Day 2 · 13 March 2025 · See you in the quantum future! ⚛️