Algorithms

Spring 2013
course
navigation

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

wikipedia
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.

Kruskal's algorithm

wikipedia
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

wikipedia

Floyd's algorithm

wikipedia
http://cs.marlboro.edu/ courses/ spring2013/algorithms/ notes/ Feb_28
last modified Thursday February 28 2013 11:13 am EST

attachments [paper clip]

     name last modified size
   prims.py Feb 28 2013 11:13 am 1.97kB    weighted_graphs.py Feb 28 2013 11:11 am 5.77kB