Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2012:journals:jeanpaul:chapterfour_sectionvi [2012/03/01 02:48] – mugabej | courses:cs211:winter2012:journals:jeanpaul:chapterfour_sectionvi [2012/03/01 03:54] (current) – [Implementing Kruskal's Algorithm] mugabej | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| * ** Union(A, B) ** : merges sets A and B into one set | * ** Union(A, B) ** : merges sets A and B into one set | ||
| * Goal implementation: | * Goal implementation: | ||
| + | * ** MakeUnionFind(S) **: returns the Union-Find data structure on set S where all elements are in separate sets. | ||
| + | * Example of such a set: A connected component with no edges | ||
| + | * Goal Implementation: | ||
| * The sets obtained will be the connected components of the graph | * The sets obtained will be the connected components of the graph | ||
| * So, for a given node u, Find(u) returns the name of the component containing u | * So, for a given node u, Find(u) returns the name of the component containing u | ||
| Line 27: | Line 30: | ||
| * If Find(u) ≠ Find(v), then Union(Find(u), | * If Find(u) ≠ Find(v), then Union(Find(u), | ||
| * The ** Union-Find ** data structure maintains components of a graph only when we add edges, not when we delete them | * The ** Union-Find ** data structure maintains components of a graph only when we add edges, not when we delete them | ||
| - | * | + | * The "name of the set" returned by Union-Find will be arbitrary |
| + | \\ | ||
| + | ==== A simple Data Structure | ||
| + | | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | |||
| + | >>>>>>>>>>>>>>>>> | ||
| + | \\ | ||
| + | ==== A Better Implementation for Union-Find ==== | ||
| + | \\ | ||
| + | * Instead of using an array, we now use a pointer-based implementation | ||
| + | * With this implementation: | ||
| + | |||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | |||
| + | ==== Implementing Kruskal' | ||
| + | |||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>> | ||
| + | |||
| + | ( The above algorithm, is from the class discussion) | ||
| + | \\ | ||
| + | \\ | ||
| + | Kruskal' | ||
| + | \\ | ||
| + | \\ | ||
| + | This section was also interesting, | ||
