Lesson 12 of 15
The Deutsch Algorithm
Quantum Speedup
The Deutsch algorithm was the first quantum algorithm to demonstrate a speedup over classical computation. It solves a specific problem in 1 query that classically requires 2.
The problem: Given a function , determine if is:
- Constant: (always outputs 0, or always outputs 1)
- Balanced: (outputs 0 for one input and 1 for the other)
Classically, you must evaluate and separately — 2 queries.
The Deutsch algorithm evaluates in quantum superposition, getting the answer in 1 query.
The algorithm's outcome is determined by :
- 0 → constant
- 1 → balanced
def deutsch(f):
if f(0) == f(1):
return "constant"
else:
return "balanced"
There are exactly 4 possible functions:
| Function | Type | ||
|---|---|---|---|
| always 0 | 0 | 0 | constant |
| always 1 | 1 | 1 | constant |
| identity | 0 | 1 | balanced |
| NOT | 1 | 0 | balanced |
Your Task
Implement deutsch(f) that classifies the function. Then define the four possible functions and test each one.
Python runtime loading...
Loading...
Click "Run" to execute your code.