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

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

View Full Document Right Arrow Icon
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”
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
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}
Background image of page 6
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}
Background image of page 7

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

View Full DocumentRight Arrow Icon
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 
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online