Apr 16
end of term
Proposal for a final project due next Tuesday.
I'll have a list of suggested topics by Thursday,
but essentially you're welcome to pick something
along the lines of what we've been doing.
The idea is to pick one, do a bit of online research
or look into one of the algorithms from
skiena's reference section, implement
it, explain it, and write it up.
new business
Dynamic programming - chapter 8 in Skiena.
We'll be primarily looking at the knapsack problem
as an example.
I found the textbook hard to follow for this
material. But there are many online sources;
google "dynamic programming" and "knapsack problem".
What we've done so far:
- basic ideas :
- O() notation
- size N and representation of problem
- numerical experiments and graphs
- data structures :
- API
- stack, queue, binary heap, hash (i.e. dictionary)
- sorting problems - several variations
- graph problems
- tree search: depth vs breadth
- several other classics
- approaches :
- brute force (i.e. try everything)
- divide and conquer (i.e. binary search)
This week a new well-known approach : the badly named
"dynamic programming".
Usefully primarily for combinatoric search problems.
The basic is to state the problem in terms
of smaller ones, then do it recursively
... BUT save results - don't calculate anything twice.
Equivalently, if the ordering of the smaller problems
is clear, we can explicitly loop over them.
The memoize.py fibonocci we looked at last week
is one of these.
- fibonacci
- binomial coefficients
- knapsack problem
- do this one in class
- 1st with brute force
- 2nd with 'dynamic programming'
We did the brute force coding in
class; the file is in that folder
named knapsack_1_in_class.py .
We discussed the dynamic programming
version, and agreed to code it in
class on Thursday.