Beruflich Dokumente
Kultur Dokumente
Topic Overview
Definitions and Representation Minimum Spanning Tree: Prim's Algorithm Single-Source Shortest Paths: Dijkstra's Algorithm Connected Components
Spanning Tree
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Prims Algorithm
2 3 1
1 3 2 2
3 3
3 3
Prims Algorithm
foreach vertex v v.key = root.key = 0 pq = new PriorityQueue(V) while pq is not empty v = pq.deleteMin() foreach u in adj(v) if v is in pq and cost(v,u) < u.key pq.decreaseKey(u, cost(v,u))
Complexity: O((V+E)log V)
foreach vertex v v.key = root.key = 0 pq = new PriorityQueue(V) while pq is not empty v = pq.deleteMin() foreach u in adj(v) if v is in pq and cost(v,u) < u.key pq.decreaseKey(u, cost(v,u))
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 4 1 3 5 1 2 4 3 1 4
3 3
Kruskals Algorithm
3 2 3 1 2 1 4 1 2
Kruskals Algorithm
while there are unprocessed edges left pick an edge e with minimum cost if adding e to MST does not form a cycle add e to MST else throw e away
Data Structures
How to pick edge with minimum cost?
Use a Priority Queue
Connected Components
The connected components of an undirected graph are the equivalence classes of vertices under the ``is reachable from'' relation.
Part (b) is a depth-first forest obtained from depth-first traversal of the graph in part (a). Each of these trees is a connected component of the graph in part (a).