Jan 26
Discuss the homework due today - I have posted
my answers which I will unlock and review.
Homework for Thursday is up.
Questions about anything?
OK, going on ...
analysis & big O notation
Browse through and discuss the material
in the Analysis chapter of the text.
- O() notation
- time in "steps" or "seconds"
- deriving run time (in steps) from the code
- measuring run time in numerical experiments
- O() runtime of various python built-in methods and data types
- the anagram problem : several different approaches
run time practicalities
How many steps is practical for a program that
runs in a few minutes?
Demonstrate explicitly. Answer : about 1e8 .
What does this imply about the size N of a
manageable problem for an algorithm that is
- O(N!)
- O(2N)
- O(N2) - how does this compare to N3?
- O(N log(N)) - and which base should we use?
- O(N)
- O(log(N))
Turns out there's an important distinction between
problems which are "hard" (i.e. impractical to
do for large N on a computer) and "easy" (i.e.
doable for fairly large N). Essentially it comes
down to exponential (hard) or polynomial (easy).
(I'm oversimplifying here - the specifics do matter.
But this is the "big picture".)
There are formal math-ish versions of
subsets of these categories, named P (polynomial)
and NP. No, NP is not "not polynomial";
it stands for "nondeterministic polynomial",
and is sort-of polynomial on a quantum computer.
(There are problems harder than NP.)
One of the biggest outstanding theoretical
problems in CS is whether problems that
seem to be in P or NP are really different,
or whether we're just not clever enough
to find fast algorithms for the NP problems.
Most everyone believes that NP problems
are intrinsically hard, and cannot be
computed quickly ... but this has not
yet been proven.
homework
I'm asking you to look at the substring problem :
>>> is_substring("one", "zero one two")
True
This is actually a classic and important problem.
Please do try to find an algorithm (not the
most efficient one) on your own. We'll talk
about tricky approaches later.
measuring execution time
Discuss ways to measure execution time of something that happens fast:
- put it it in a big loop, and use python's "time" library
- or use python "timeit" library