You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disjoint set data structure can have the following APIs,
Set
The class Set will represent the notion of disjoint sets with respect to the above data structure. Attributes
key - Any valid key which can be used to uniquely identify this set.
data - Any valid data or pointers to data can be stored through this.
parent - The parent of this set.
size - The size of the set.
rank - The rank of the set.
We cannot use static data classes as the data attribute will be dynamic.
DisjointSetTree
This will represent the notion of disjoint set tree of DisjointSet. Attribute tree - A python dict for key to DisjointSet mapping. Hashing here will help us quickly figure out whether a DisjointSet is there inside the tree.
Methods
make_set(key, data) - It will make a new set as described in the references.
find(key) - Finding the root of a particular disjoint set sub tree using path-splitting logic.
union(key1, key2) - Taking union of sets with given keys by size.
Description of the problem
Disjoint set data structure can have the following APIs,
Set
The class
Set
will represent the notion of disjoint sets with respect to the above data structure.Attributes
key
- Any valid key which can be used to uniquely identify this set.data
- Any valid data or pointers to data can be stored through this.parent
- The parent of this set.size
- The size of the set.rank
- The rank of the set.We cannot use static data classes as the
data
attribute will be dynamic.DisjointSetTree
This will represent the notion of disjoint set tree of
DisjointSet
.Attribute
tree
- A pythondict
forkey
toDisjointSet
mapping. Hashing here will help us quickly figure out whether aDisjointSet
is there inside the tree.Methods
make_set(key, data)
- It will make a new set as described in the references.find(key)
- Finding the root of a particular disjoint set sub tree using path-splitting logic.union(key1, key2)
- Taking union of sets with given keys by size.Example of the problem
References/Other comments
.. [1] https://en.wikipedia.org/wiki/Disjoint-set_data_structure
This is not open for contributions.
The text was updated successfully, but these errors were encountered: