Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| courses:cs211:winter2012:journals:jeanpaul:chapterfour_sectionvi [2012/03/01 02:04] – created mugabej | courses:cs211:winter2012:journals:jeanpaul:chapterfour_sectionvi [2012/03/01 03:54] (current) – [Implementing Kruskal's Algorithm] mugabej | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| * And the graphs grows over time by inserting edges between certain pairs of nodes. | * And the graphs grows over time by inserting edges between certain pairs of nodes. | ||
| * Goal: Maintain a set of connected components of the graph being processed throughout the whole operation | * Goal: Maintain a set of connected components of the graph being processed throughout the whole operation | ||
| + | * With this algorithm, we develop a data structure called the ** Union-Find ** structure | ||
| + | * The ** Union-Find ** data structure stores a representation of the components in a way that supports fast searching and updating | ||
| + | * This data structure is used to efficiently implement Kruskal' | ||
| + | |||
| + | >>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | ||
| + | \\ | ||
| + | ==== The Problem ==== | ||
| + | * Operations: | ||
| + | * ** Find(u) **: returns name of set containing u | ||
| + | * It can be used to find if two nodes //u// and //v// are in the same set by simply checking if Find(u) = Finf(v) | ||
| + | * Goal implementation: | ||
| + | * ** Union(A, B) ** : merges sets A and B into one set | ||
| + | * 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 | ||
| + | * So, for a given node u, Find(u) returns the name of the component containing u | ||
| + | * To add an edge (u,v) we first test if Find(u) = Find(v) | ||
| + | * 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 "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, | ||
