CS 10
Limits of computing
Today’s agenda
Complexity
How fast is a program?
Examples
Big O notation | Name | Example |
O(1) | constant | Pick first element of a list |
O(log(n)) | logarithmic | Use binary search to find an element in a sorted list |
O(n) | linear | Read a file’s contents |
O(n log(n)) | superlinear1 | Sort a list2 |
O(nc) [e.g. n2] | polynomial | Introduce everyone to everyone else |
O(cn) [e.g. 2n] | exponential | Recursive Fibonacci |
Example: exponential function
Running this with n = 100 didn’t finish before these slides were written (6+ hours)!
Each call makes 2 more calls (we say this has a “branching factor” of 2)
This is O(2n)
Just how bad is it?
Today’s agenda
Tractability
Tractable vs intractable
Intractable problems
Today’s agenda
P vs NP
Solution vs verification
Example: Where’s Waldo
Finding a solution:
Example: Where’s Waldo
Verifying a solution:
Finding a solution is slow, but verifying a solution is fast
Aside: doing assignments vs grading assignments…?
Another example
Write a program to find the dumbest reddit post
Here, finding a solution and verifying a solution are both slow
Note: both these examples are tractable (technically)
P vs NP
The knapsack problem
Given a bag with a set capacity, and several items with both size and value:
Naive solution: just try every possible configuration
To make this an NP problem, we need to rephrase the question:
P vs NP
Reduction
[tldr] If you have something that can solve B, can you use that to solve A?
More formally, A reduces to B means:
Reduction example
If you have a program that can square a number, can you write a program to cube a number?
Formally:
Reduce A to B
“Mathy” way to show that cubing something is “no harder than” squaring something
Can you also reduce B to A?
P vs NP
Time for some hand-waving:
For the sake of today:
P vs NP
P vs NP, in conclusion
20
(oops)
Today’s agenda
The halting problem
The halting problem
For a program P with input I, does this program halt?
Let’s denote this as halt(p, i), which outputs “true” or “false”
Spoiler: halt does not exist
Proof by contradiction
What does halts_on_self(broken) do?
The halting problem
Today’s agenda
Decidability and computability
Decidability vs computability
Decidability and computability talk about different classes of problems
It’s usually easy to convert between decision problems and general problems
Today’s agenda
Takeaways
Takeaways
Today’s agenda
Memes to end the day
Approximation to “does P = NP?”:
Memes to end the day
Memes to end the day
Memes to end the day
Memes to end the day
“Some engineer out there has solved P=NP and it's locked up in an electric eggbeater calibration routine.”