Recitation 11 should be submitted following directions at:
submissions with deadlines
|
Note: As of < Fri Apr 13 19:51:31 CDT 2012 > I put up the submission program for this recitation and tested it.
Relax(u, v, w)
if v.d > u.d + w(u, v) v.d = u.d + w(u, v) v.π = u |
The set S of vertices on lines 2 and 6 is only used for the correctness proof, so it need not be implemented. The function puts all vertices into a minimum priority queue, and so each Extract-Min returns the vertex with the smallest remaining d value. (The priority queues we got from heaps were max priority queues.) You may use any kind of min-priority queue that you can find or put together. Probably the simplest solution is to fake such a queue, meaning to store the list of values and repeatedly search for the vertex with the current smallest value of the field d, returning and deleting it, without worrying about performance.
More about the queue: Beware! The d fields change from step to step during execution, so the queue will need the latest d values to return the proper vertex. In writing this code, I did not try to use a true priority queue based on heaps, but instead created a simple low-performance queue. Nevertheless, I found this part the most confusing, since the priority of removal is based on the latest values of the d fields. I did this algorithm a long time ago and thought it was easy; you could use an extra field (color black or white) on each vertex to keep track of those vertices not yet processed (color=white). Then repeatedly go down the list looking for the white vertex with smallest d value. You must carry out at least two runs of your program that implements Dijkstra's algorithm, including both RUN A, and RUN B below: