# L07 - Implementing Kruskal's algorithm How to determine...

This preview shows pages 1–9. Sign up to view the full content.

CS0250, Set 7 Implementing Kruskal’s algorithm How to determine whether adding an edge will cause a cycle? Observation :  During the execution of the algorithm, the set of edges in the  solution (red edges) forms a set of disjoint trees. a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 Four “subtrees”

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS0250, Set 7 Observation :  During the execution of the algorithm, the set of edges in the  solution (red edges) forms a set of disjoint trees. (1) Adding (u,v) where u and v are in the same subtree  cycle. a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 cycle
CS0250, Set 7 Implementing Kruskal’s algorithm Observation :  During the execution of the algorithm, the set of edges in the  solution (red edges) forms a set of disjoint tree. (2) Adding (u,v) where u and v are in the different subtrees   no cycle. a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 no cycle

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS0250, Set 7 Implementing Kruskal’s algorithm Idea: Remember the sets of vertices of the subtrees. (We agree that  isolated vertex is also a subtree.) a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 The “forest” (i.e., set of subtrees):     {a}, {b}, {i,c}, {h,g}, {d,e,f} These are sets.
CS0250, Set 7 Implementing Kruskal’s algorithm Adding edge (d,f).  Since  Find-Set (d) =  Find-Set (f),   d, f are in the  same  set and hence are in the  same  tree   cycle and don’t add (d,f) to the current solution set. a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 The “forest” (i.e., set of subtrees):     {a}, {b}, {i,c}, {h,g}, {d,e,f} return the set the argument  belongs in the  current forest.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS0250, Set 7 Implementing Kruskal’s algorithm Adding edge (i,h).  Since Find-Set(i) ≠ Find-Set(h),   i, h are in the  different  sets, and hence in  different  trees. no cycle and add (i,h) to the solution set, and “merge” the two subtrees by  Union (Find-Set(i), Find-Set(h)). a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 The “forest” (i.e., set of subtrees):     {a}, {b}, {i,c}, {h,g}, {d,e,f}
CS0250, Set 7 Implementing Kruskal’s algorithm Adding edge (i,h).  Since Find-Set(i) ≠ Find-Set(h),   i, h are in the  different  sets, and hence in  different  trees. no cycle and add (i,h) to the solution set, and “merge” the two subtrees by  Union (Find-Set(i), Find-Set(h)). a i b h g c f d e 4 8 11 8 2 4 1 2 7 9 10 14 7 The “forest” (i.e., set of subtrees):     {a}, {b}, {i,c,h,g}, {d,e,f}

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS0250, Set 7 Time complexity No. of Make-set:|V|;  No. of Find-Set:2|E|;  No. of Union:|V|-1. We describe a data structure which takes O(|E|log |V|) time for all these
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 44

L07 - Implementing Kruskal's algorithm How to determine...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online