Lecture Note
University
University of California San DiegoCourse
CSE 100/101 | Data Structures and AlgorithmsPages
2
Academic year
2023
anon
Views
36
Analyzing the Disjointed Set Data Structure in-Depth A data structure called a disjointed set is used to keep track of a number of different sets. A disjointed set is mostly used to develop union-findalgorithms or to keep track of a graph's various elements. We will give athorough explanation of the disjointed set data structure in this post, covering itsdefinition, implementation, and numerous techniques for increasing itseffectiveness. What is a Disjointed Set Data Structure? A group of sets with no shared elements is referred to as a disconnected set. The sets are therefore not connected. A collection of disjoint sets are trackedusing the disjointed set data structure, which also offers an effective method formerging and discovering the sets. A disconnected set can be used for thefollowing primary operations: ● Create a singleton set with just one element using the makeset procedure. ● Find: This operation is used to identify the set that a specific elementbelongs to. ● Union: This procedure joins two sets together to create one larger set. Implementing a Disjointed Set Although there are various ways to implement the fragmented set data structure, the most popular one uses an array to hold the set information. In thissolution, the disconnected set's elements are represented by integers, and thesmallest element in each set serves as the ID for that set. One line of code can be used to accomplish the MakeSet operation. We set the smallest of I to be equal to I in order to produce a singleton set that onlycontains element i. Another simple operation that can be carried out in constanttime is the Find operation. We just return the value of smallest[i] in order to getthe ID of the set containing element i. Contrarily, the Union operation is a little bit trickier. In order to combine two sets that contain the items I and j, we must first identify the set's ID byusing Find(i) and save the outcome in the variable i id. The ID that results from
doing the same for element j is then saved in the variable j id. If i id and j id areequal, then I and j already belong to the same set and no further action isrequired. The two sets must be combined if i id and j id are different. To do this,we must update the smallest array for each object whose ID is either i id or j id.This operation has a linear running time. Enhancing the Performance of Unconnected Sets A disjointed set's effectiveness can be increased in a number of ways, including: ● Using route compression: In this method, the path from each element tothe set's root is compressed every time a Find operation is run by directlyconnecting each node to the root. ● By using the union by rank method, the sets are combined according totheir rank rather than their size. The height of the tree used to symbolize aset is used to determine its rank. ● Combining path compression and union by rank can result in afragmented set data structure that is more effective. For tracking collections of discontinuous sets, the disjointed set data structure is an effective tool. It can be used in a variety of ways, and methodslike path compression and union by rank can increase its effectiveness.
Analyzing the Disjointed Set Data Structure
Please or to post comments