Sets & Disjoint Set Union
Sets & Disjoint Set Union
Bheekya D
Definition and properties of sets and disjoint sets
● A set is a collection of distinct elements.
○ Examples: when n = 10, the elements can be partitioned into three
sets as following;
■ S1 = {1,7,8,9}
■ S2 = {2,5,10} and
■ S3 = {3,4,6}
● Sets Si and Sj are said to be Disjoint Sets iff Si ∩ Sj = Ø.
○ Examples:
■ S1∩ S2 = Ø
■ S1∩ S3 = Ø
■ S2∩ S3 = Ø
■ S1∩ S2∩ S3 = Ø
Definition and properties of sets and disjoint sets
● Sets and Disjoint-sets are special type of data structures, are used in
implementing some algorithms(Kruskal's algorithm).
● In Practice, sets are represented by numbers and they might denotes
the indices of the array.
● Sets and disjoint sets are are represented by forest which is called
collection of trees.
Definition and properties of sets and disjoint sets
Let us process the following sequence of union operations using a simple union algorithm
3 n
2
2 N-1
1
1
Finally, we will get a degenerated tree
Suppose, if we want to perform the following sequence Find operations
Although these two algorithms are very easy to state, but their performance characteristics
are not very good, we can improve the performance of our union and find algorithms by
avoiding the creation of degenerated trees. To do this, we make use of a weighting rule for
Union(i, j).
Definition: Weighted rule Union(i, j):- If the number of nodes in the tree
with root i is less than the number in the tree with root j, then make j the
parent of of i, otherwise make i is the parent of j.
Note: to implement weighted rule, we need to know how many nodes there are in every tree, maintain a
count field in the root of every tree, then count[i] equals the number of nodes in that tree.
Here, avoided the creation of degenerated tree and time required to process
all the n finds is only O(n).
Still we can the improve the performance of FIND operation, using collapsing rule.
According to this theorem the maximum time to process a find is at most O(log n) if there
are n elements in a tree.
Note: Tree generate
using the weighted
union algorithms.
Suppose if we want Find(8) 8-times(sequence of finds), we will see how the collapsing
find algorithm will give the better result than simple FIND.
If Simple FIND is used, find(8) 8-times requires 24 moves.
If we used collapsing find it will required 13 moves only.(3 moves for finding root, 3
moves for collapsing and 7moves requires for remaining 7 finds).
Collapsing Find algorithm doubles the time for individual find. However, it reduces the
worst-case time over a sequence of finds.
AND/OR Graphs,
The alpha value of a max position is defined to be the minimum possible value for that
position. If the value of a min position is determined to be less than or equal to the alpha
value of its parent, then we may stop generation of the remaining children of this min position.
The beta value of a min position is the maximum possible value for that position. If the value of
a max position is determined to be greater than or equal to the beta value of its parent node,
then we may stop generation of the remaining children of this max position.
Postorder evaluation of a game tree using alpha-beta pruning