29 November 2004: Topological sort: add the vertex to the beginning of list *after* you visit all its neighbors. Dijkstra's algorithm: shortest paths problem in a weighted digraph (how do you represent a weighted graph?) single-pair versus single-source start with initial vertex need "parents", "distances", and "colors" parents -- we build a vector indicating which node preceds it in the shortest path. distances -- we keep track of the current shortest path to each node as it's found. Initially, each distance is set to "infinity" except for the start node (which is 0) colors -- indicating whether we've searched a nodes neighbors or not Algorithm: - find white node u with smallest distance to the source (initially, this is the source) - color u black - for each of u's neighbors v: - let new-dist be distance[u] + weight(u,v) - if new-dist <= distance[v]: - set parent[v] to be u - set distance[v] to be new-dist - repeat until all nodes are black Then, we can construct the shortest path from any node to u by tracing through the "parent" array. We reverse the path to get the shortest path from u to that node. Run time: O(E V^2) Can do O(E log(V)) -- how?