Feb 28
Tues homework looked good. The python I showed
last class can be used to generate the structures and
search paths ; see
feb26 homework.py
Continue our discussion from last time of some classic graph algorithms
on weighted graphs.
First, need to modify our data structure a
bit to accomodate the weights and any
other "marks" we want to include while
running the algorithms.
Adjacency data structure for weighted graphs :
adjacency = {
vertex_begin : [ {vertex_end:xxx, distance:yyy} ... ],
...
}
The idea is to put more more information
into the elements of the list, in addition
to the name of the vertex.
Here is an implementation of a this in python
along with an API similar to the one we saw before :
weighted_graphs.py
The tests in that code generate the weighted graph on pg 196
in the text :
In class we wrote (and debugged!) the attached prims.py
which implements a simple version of prims,
without an efficient way to get the closest vertex
not in the tree. But hey - it works.
Minimum spanning tree
Prim's algorithm
First, explain what this is trying to do and how it works.
Using weighted_graphs.py ,
write code in class to
implement Prim's algorithm.
- First take : don't worry about efficiency, just get something that works.
- Second take : keep track of nearest neighbors as in text.
Kruskal's algorithm
Again, start by explaining how this works.
Depending on time, write some code ...
And/or continue on to the other graph algorithms in this chapter :
Shortest path
Dijkstra's algorithm
Floyd's algorithm