Announcements PA3/HW3 av, due 04/09, 11:59p.
5 3 4 5 4 4 4 4 4 4 3 3 3 3 3 3 2 2 2 2
Prims Algorithm (undirected graph with unconstrained edge weights) : - - PowerPoint PPT Presentation
Announcements PA3/HW3 av, due 04/09, 11:59p. 5 3 3 3 4 2 5 3 4 4 2 3 4 4 2 3 3 2 4 4 Prims Algorithm (undirected graph with unconstrained edge weights) : Initialize structure: adj mtx adj list 1. For all v, d[v] =
5 3 4 5 4 4 4 4 4 4 3 3 3 3 3 3 2 2 2 2
Initialize structure:
1. For all v, d[v] = “infinity”, p[v] = null 2. Initialize source: d[s] = 0 3. Initialize priority (min) queue
Repeat these steps n times:
If cost(v,w) < d[w] d[w] = cost(v,w) p[w] = v
Depends on density of the graph: Sparse Dense
adj mtx adj list heap
O(n2 + m log n) O(n log n + m log n)
Unsorted array
O(n2) O(n2)
Given a start vertex (source) s, find the path of least total cost from s to every vertex in the graph. Input: directed graph G with non- negative edge weights, and a start vertex s. Output: A subgraph G’ consisting of the shortest (minimum total cost) paths from s to every other vertex in the graph.
10 7 3 5 7 3 3 2 2 6
Dijkstra’s Algorithm (1959)
10 7 3 5 7 3 3 2 2 6
Initialize structure:
1. For all v, d[v] = “infinity”, p[v] = null 2. Initialize source: d[s] = 0 3. Initialize priority (min) queue
Repeat these steps n times:
If (_________________ < d[w]) d[w] = ______________ p[w] = v
Initialize structure:
1. For all v, d[v] = “infinity”, p[v] = null 2. Initialize source: d[s] = 0 3. Initialize priority (min) queue
Repeat these steps n times:
If d[v] + cost(v,w) < d[w] d[w] = d[v] + cost(v,w) p[w] = v
Initialize structure:
1. For all v, d[v] = “infinity”, p[v] = null 2. Initialize source: d[s] = 0 3. Initialize priority (min) queue
Repeat these steps n times:
If d[v] + cost(v,w) < d[w] d[w] = d[v] + cost(v,w) p[w] = v
Depends on density of the graph: Sparse Dense
adj mtx adj list heap
O(n2 + m log n) O(n log n + m log n)
Unsorted array
O(n2) O(n2)
shortest path to the first k vertices it visits (the cloud). …
cloud through which ____ passes. Call it y.
path from s to u, since Q is shortest path out of the cloud.
vertex is incorrect.
10 7 13 5 7 2 3
2 6
Initialize structure: Repeat these steps:
1. Label a new (unlabelled) vertex v, whose shortest distance has been found 2. Update v’s neighbors with an improved distance
Dijkstra’s Algorithm (1959)