This action might not be possible to undo. Are you sure you want to continue?

Discussion Session 4 Instructor: Dr Alon Efrat TA : Pooja Vaswani 02/28/2005

Topics Graphs Minimum Spanning Trees ± Kruskal ± Prim 2 .

connected graph G = (V.E) Weight function W: E p R (assigning cost or length or other values to edges) Spanning tree: tree that connects all the vertices (above?) Minimum spanning tree: tree that connects all the vertices and minimizes w(T ) ! w(u . v ) § ( u . v )T 3 .Minimum Spanning Trees Undirected.

At each step. an edge is determined that can be added to A without violating this invariant.Generic MST Algorithm Generic-MST(G. 4 .v) that is safe for A 4 AnA{(u.v)} 5 return A Safe edge edge that does not destroy A s property The algorithm manages a set of edges A maintaining the following loop invariant Prior to each iteration. Such an edge is called a Safe Edge. A is a subset of some minimum spanning tree. w) 1 An// Contains edges that belong to a MST 2 while A does not form a spanning tree do 3 Find an edge (u.

where x Si 5 .e.Sj} {Si Sj} ± FindSet(S.a collection of disjoint sets ± MakeSet(S. i.Kruskal's Algorithm Edge based algorithm Add the edges one at a time. x): returns unique Si S.Sj): S n S ± {Si.x): S n S {{x}} ± Union(Si.. in increasing weight order The algorithm maintains A ± a forest of trees. An edge is accepted it if connects vertices of distinct trees We need a data structure that maintains a partition.

Kruskal's Algorithm The algorithm adds the cheapest edge that connects two trees of the forest MST-Kruskal(G.v) E. in order by nondecreasing weight do 06 if Find-Set(u) { Find-Set(v) then 07 A n A {(u.v)} 08 Union(u.v) 09 return A 01 02 03 04 05 6 .w) A n for each vertex v V[G] do Make-Set(v) sort the edges of E by non-decreasing weight w for each edge (u.

Kruskal Example 7 .

Kruskal Example (2) 8 .

Kruskal Example (3) 9 .

Kruskal Example (4) 10 .

Kruskal Running Time Initialization O(V) time Sorting the edges 5(E lg E) = 5(E lg V) (why?) O(E) calls to FindSet Union costs ± Let t(v) ± the number of times v is moved to a new cluster ± Each time a vertex is moved to a new cluster the size of the cluster containing the vertex at least doubles: t(v) elog V ± Total time spent doing Union § t (v ) e V log V Total time: O(E lg V) vV 11 .

key[v] = g. if no such edge exists 12 . one vertex at a time A cloud covering the portion of T already computed Label the vertices v outside the cloud with key[v] ± the minimum weigth of an edge connecting v to a vertex in the cloud.Prim-Jarnik Algorithm Vertex based algorithm Grows one tree T.

r) 01 02 03 04 05 06 07 08 09 10 11 Q n V[G] // Q ± vertices out of T for each u Q key[u] n g key[r] n 0 T[r] n NIL while Q { do u n ExtractMin(Q) // making u part of T for each v Adj[u] do if v Q and w(u.v) 13 .w.Prim-Jarnik Algorithm (2) MST-Prim(G.v) < key[v] then T[v] n u key[v] n w(u.

Prim Example 14 .

Prim Example (2) 15 .

Prim Example (3) 16 .

- Multi Algoerithm Kruppa-slides
- Graph Algorithms
- Problems Solved by Greedy Method
- Sir's on red-black
- Dijkstras Algorithm
- Algorithms in tics 2002
- 26EFF6B0d01
- Chap 8 Dynamic Programming
- Berkeley
- Flow Networks
- Sir's on Dynamic Programming
- Hw2 Solutions
- L-13 Dynamic Programming
- Fib On
- Solution to Midterm 1
- Art of Programming Contest SE for Uva
- a0505- Mathematical Foundations of Computer Science
- Computer Networks
- Radix Search Tree
- Flow Networks
- Sir's on Basics of Algorithm
- Prims algorithem
- Algorithms and Data Structures
- Amortized Analysis
- Planning Algorithm
- Problems on Algorithms (2002)
- 27287326-Algorithms-and-Data-Structures
- PrimsKrushkals

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd