CS301 – Data Structures
Lecture No. 36
___________________________________________________________________
Data Structures
Lecture No. 36
Reading Material
Data Structures and Algorithm Analysis in C++
Chapter. 8
8.4, 8.5, 8.6
Summary
•
Running Time Analysis
•
Union by Size
•
Analysis of Union by Size
•
Union by Height
•
Sprucing up find
•
Timing with Optimization
Running Time Analysis
In the previous lecture, we constructed up trees through arrays to implement disjoint sets.
u
nion
and
find
methods along with their codes were discussed with the help of figures.
We also talked about the ways to improve these methods. As far as the
union
operation is
concerned, considering the parent array, it was related to changing the index of the array.
The root value of the merging tree was put into that. In case of find, we have to go to the
root node following the up pointers.
While studying the balanced trees, we had constructed a binary search tree from the
already sorted data. The resultant tree becomes a linked list with height N. Similar kind
of risks involved here. Suppose, we have eight members i.e.1, 2, 3, 4, 5, 6, 7 and 8 as
discussed in an example in the previous lecture. Suppose their unions are performed as
union(1,2), union(2,3), union(3,4) and so on up to union(7,8). When the trees of these
unions are merged together, there will be a longer tree of height 8. If we perform a find
operation for an element that is present in the lowest node in the tree then N1 links are
traversed. In this particular case, 81=7 links.
We know that with reduced tree (with lesser height), the time required for
find
operation
will also be reduced. We have to see whether it is possible to reduce the size (in terms of
height) of the resultant tree (formed after unions of trees). Therefore, our goal is:

Goal
: Modify
union
to ensure that heights stay small
We had already seen this goal in the last slide of our previous lecture, which is given
below in full:
Page 1 of 13