CS252 Algorithms Friday, 19 April 2024 + What's up? + Shortest paths with Old Man Edsger - Walk through an example - What the heck is going on with that notation? - Why does it work? - Is it greedy? - How are we gonna implement this thing? P = priority queue of edges (the edges leaving the orange blob) priority for edge (u,v) will be d[u] + w(u,v) "remove from P" -- grab the minimum-endpoint-distance edge e - Negative edges? + Applications? [Jeff's version for today] Given: connected* graph** G = (V, E) weight function W: E -> R+ (i.e., positive real numbers on each edge) starting node s ∈ V Produce: shortest-path distances*** from s to all nodes Algorithm: S = {s} (the "settled" nodes) O(1) d[s] = 0; d[u] = infinity for all u != s O(|V|) while S != V: |V|-1 iterations let e = (u,v) be such that u ∈ S, v !∈ S, ??? and d[u] + w(u,v) is as small as possible d[v] = d[u] + w(u, v) O(1) (assuming w is O(1)???) add v to S O(1) * connected makes the loop condition easier; we can modify to handle arbitrary G ** same algorithm works for digraphs *** we can modify to produce the paths themselves in addition to the distances