SlideShare a Scribd company logo
1 of 25
Lecture 10
Disjoint Set ADT
Preliminary Definitions
A set is a collection of objects.
Set A is a subset of set B if all elements of A are in B.
Subsets are sets
Union of two sets A and B is a set C which consists of all
elements in A and B
Two sets are mutually disjoint if they do not have a
common element.
A partition of a set is a collection of subsets such that
Union of all these subsets is the set itself
Any two subsets are mutually disjoint
S = {1,2,3,4}, A = {1,2}, B = {3,4}, C = {2,3,4}, D = {4}
Is A, B a partition of S?
Is A, C partition of S?
Yes
Is A, D partition of S?
No
No
Union and Find Operations
Operations on partitions.
Union
Need to form union of two different sets of a partition
Find
Need to find out which set an element belongs to
Every set in the partition has a number.
The numbers can be anything as long as different sets have
distinct numbers.
Find(a) returns the number of the set containing a.
Can two different sets contain the same element?
No, the sets in a partition are disjoint
Disjoint Set Data Structure
The set is represented by the root of the tree.
The number assigned to a set is the number of the
root element.
Every element has a number.
Elements of a set are stored in a tree (not necessarily binary)
B = {3, 4}
3
4
B is assigned number 3
Are the numbers distinct for different sets?
No two sets have the same root as they are disjoint,
thus they have distinct numbers
Find(a) returns the number of the root node of the
tree containing a.
Union operation makes one tree sub-tree of another
Root of one tree becomes child of the root of another.
B = {3, 4}
3
4
Find(4) returns? 3
Find(3) returns? 3
B = {3, 4}
3
4
A = {1,2}
1
2
Want to do A union B
We have:
1
2
3
4
Tree Representation
Will use an array based representation, array S
Let the elements be 1,2,….N
S[j] contains the number for the parent of j
S[j] = 0 if j is the root.
Initially all trees are singletons
Trees build up with unions.
Note that we don’t use any pointers here.
B = {3, 4}
3
4
A = {1,2}
1
2
Want to do A union B
We have:
1
2
3
4
0 1 0 3
S 0 1 1 3
S
Pseudo Code for Find
Find(a) {
If S[a] = 0, return a;
else Find(S[a]);
return;
}
Complexity? O(N)
Pseudo-Code for Union
Union(root 1, root 2)
{
S[root2] = root1;
}
Complexity? O(1)
More Efficient Union
Will improve the worst case find complexity to log N
When we do a union operation make the smaller tree a
subtree of the bigger one
Thus the root of the smaller subtree becomes a child
of the root of the bigger one.
A = {1,2,3} B = {4}
Root of B is root of A after union, B is subtree of A
Alternatively, union operation can be done by height as well
Tree of lesser height is made subtree of the other.
We consider only size here.
Array storage changes somewhat.
If j is a root, S[j] = - size of tree rooted at j
If j is not a root, S[j] = parent of j
Why is S[j] not equal to the size of tree j, if j is a root?
Initially, what is the content of array S?
All elements are -1
Size of tree j is an integer, if S[j]=size of tree j and
j is root, then it would look like root of j is another
element, thus j is not root
Pseudo-Code for Union
Union(root 1, root 2)
{
If S[root2] < S[root1], S[root1] = root2;
else S[root2]=root1;
}
Complexity? O(1)
Pseudo Code for Find
Find(a) {
If S[a] < 0, return a;
else Find(S[a]);
return;
}
Complexity Analysis for Find
Operation
If the depth (distance from root) of a node A increases,
then the earlier tree consisting the node A becomes a
subtree of another.
Since only a smaller tree becomes a subtree of another,
total size of the combined tree must be at least twice
the previous one consisting A.
Each time depth of a node increases, the size of the
tree increases by at least a factor of 2.
At first every node has depth 0
Next time depth is 1, tree size is at least 2,
depth is 2, tree size is at least 4…
depth is k, tree size is at least 2k
We know that 2k <= N
Thus k <= log N
Complexity of Find operation is O(log N)
Complexity of any M operations is O(MlogN)
Depth of any tree is at most log N
Path Compression
Makes all operations almost linear in the worst case.
Whenever you do Find(j) make S[k]=Find(j) for all elements
on the path of j to the root, except the root.
All nodes on the path of j now point to the root directly
1
2
3
4
Do Find(5)
Find(5) encounters 5, 4 and 3 before reaching root 1
After Find(5):
5
1
2
3 4
5
Later Find operations will have lower costs as their depths have
been reduced.
Any Find operation reduces the cost of future ones.
Pseudo Code for New Find
Find(a) {
If S[a] < 0, return a;
else S[a]=Find(S[a]);
return;
}
Complexity Analysis
Any M operations take O(Mlog*N) if M is (N)
log*N is the number of times we take loglog….logN so as to
get a number less than or equal to 1 (log base 2, even
otherwise asymptotic order remains the same).
log*N grows very slowly with N and is less
than 4 or 5 for all practical values of N,
log*232 is less than 5
Thus the worst case complexity is linear for all practical
purposes.
Reading Assignment
Chapter 8, till section 8.61. (i.e. section 8.6.1
onwards can be omitted).

More Related Content

Similar to ee220s02lec10.ppt.........................

algebric structure_UNIT 4.ppt
algebric structure_UNIT 4.pptalgebric structure_UNIT 4.ppt
algebric structure_UNIT 4.pptDivyaRasrogi
 
Explore the foundational concepts of sets in discrete mathematics
Explore the foundational concepts of sets in discrete mathematicsExplore the foundational concepts of sets in discrete mathematics
Explore the foundational concepts of sets in discrete mathematicsDr Chetan Bawankar
 
Discrete mathematic
Discrete mathematicDiscrete mathematic
Discrete mathematicNaralaswapna
 
1. set theory
1. set theory1. set theory
1. set theorycaymulb
 
CRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huliCRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huliharshmacduacin
 
Grade 7 Mathematics Week 1.presentations
Grade 7 Mathematics Week 1.presentationsGrade 7 Mathematics Week 1.presentations
Grade 7 Mathematics Week 1.presentationsFranceAnnValmores
 
Sets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabeySets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabeyravingeek
 
Discrete Structure Mathematics lecture 1
Discrete Structure Mathematics lecture 1Discrete Structure Mathematics lecture 1
Discrete Structure Mathematics lecture 1Amr Rashed
 
Q1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptx
Q1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptxQ1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptx
Q1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptxNovyFacun1
 
Subsets Definition Types, Properties and Example Questions.pdf
Subsets Definition Types, Properties and Example Questions.pdfSubsets Definition Types, Properties and Example Questions.pdf
Subsets Definition Types, Properties and Example Questions.pdfChloe Cheney
 
POWERPOINT (SETS & FUNCTIONS).pdf
POWERPOINT (SETS & FUNCTIONS).pdfPOWERPOINT (SETS & FUNCTIONS).pdf
POWERPOINT (SETS & FUNCTIONS).pdfMaryAnnBatac1
 
Learn Set Theory
Learn Set TheoryLearn Set Theory
Learn Set Theoryyochevedl
 

Similar to ee220s02lec10.ppt......................... (20)

DM-unit-3.ppt
DM-unit-3.pptDM-unit-3.ppt
DM-unit-3.ppt
 
13038350.ppt
13038350.ppt13038350.ppt
13038350.ppt
 
algebric structure_UNIT 4.ppt
algebric structure_UNIT 4.pptalgebric structure_UNIT 4.ppt
algebric structure_UNIT 4.ppt
 
Explore the foundational concepts of sets in discrete mathematics
Explore the foundational concepts of sets in discrete mathematicsExplore the foundational concepts of sets in discrete mathematics
Explore the foundational concepts of sets in discrete mathematics
 
Discrete mathematic
Discrete mathematicDiscrete mathematic
Discrete mathematic
 
Set theory
Set theorySet theory
Set theory
 
SetTheory.ppt
SetTheory.pptSetTheory.ppt
SetTheory.ppt
 
SetTheory.ppt
SetTheory.pptSetTheory.ppt
SetTheory.ppt
 
1. set theory
1. set theory1. set theory
1. set theory
 
CRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huliCRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huli
 
Grade 7 Mathematics Week 1.presentations
Grade 7 Mathematics Week 1.presentationsGrade 7 Mathematics Week 1.presentations
Grade 7 Mathematics Week 1.presentations
 
Sets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabeySets and Functions By Saleh ElShehabey
Sets and Functions By Saleh ElShehabey
 
Discrete Structure Mathematics lecture 1
Discrete Structure Mathematics lecture 1Discrete Structure Mathematics lecture 1
Discrete Structure Mathematics lecture 1
 
Q1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptx
Q1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptxQ1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptx
Q1 Week 1 Lesson -Concepts of Sets and Operation on Sets.pptx
 
Subsets Definition Types, Properties and Example Questions.pdf
Subsets Definition Types, Properties and Example Questions.pdfSubsets Definition Types, Properties and Example Questions.pdf
Subsets Definition Types, Properties and Example Questions.pdf
 
Algebraic structures
Algebraic structuresAlgebraic structures
Algebraic structures
 
POWERPOINT (SETS & FUNCTIONS).pdf
POWERPOINT (SETS & FUNCTIONS).pdfPOWERPOINT (SETS & FUNCTIONS).pdf
POWERPOINT (SETS & FUNCTIONS).pdf
 
7-Sets-1.ppt
7-Sets-1.ppt7-Sets-1.ppt
7-Sets-1.ppt
 
Set concepts
Set conceptsSet concepts
Set concepts
 
Learn Set Theory
Learn Set TheoryLearn Set Theory
Learn Set Theory
 

Recently uploaded

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

ee220s02lec10.ppt.........................

  • 2. Preliminary Definitions A set is a collection of objects. Set A is a subset of set B if all elements of A are in B. Subsets are sets Union of two sets A and B is a set C which consists of all elements in A and B Two sets are mutually disjoint if they do not have a common element.
  • 3. A partition of a set is a collection of subsets such that Union of all these subsets is the set itself Any two subsets are mutually disjoint S = {1,2,3,4}, A = {1,2}, B = {3,4}, C = {2,3,4}, D = {4} Is A, B a partition of S? Is A, C partition of S? Yes Is A, D partition of S? No No
  • 4. Union and Find Operations Operations on partitions. Union Need to form union of two different sets of a partition Find Need to find out which set an element belongs to
  • 5. Every set in the partition has a number. The numbers can be anything as long as different sets have distinct numbers. Find(a) returns the number of the set containing a. Can two different sets contain the same element? No, the sets in a partition are disjoint
  • 6. Disjoint Set Data Structure The set is represented by the root of the tree. The number assigned to a set is the number of the root element. Every element has a number. Elements of a set are stored in a tree (not necessarily binary)
  • 7. B = {3, 4} 3 4 B is assigned number 3 Are the numbers distinct for different sets? No two sets have the same root as they are disjoint, thus they have distinct numbers
  • 8. Find(a) returns the number of the root node of the tree containing a. Union operation makes one tree sub-tree of another Root of one tree becomes child of the root of another. B = {3, 4} 3 4 Find(4) returns? 3 Find(3) returns? 3
  • 9. B = {3, 4} 3 4 A = {1,2} 1 2 Want to do A union B We have: 1 2 3 4
  • 10. Tree Representation Will use an array based representation, array S Let the elements be 1,2,….N S[j] contains the number for the parent of j S[j] = 0 if j is the root. Initially all trees are singletons Trees build up with unions. Note that we don’t use any pointers here.
  • 11. B = {3, 4} 3 4 A = {1,2} 1 2 Want to do A union B We have: 1 2 3 4 0 1 0 3 S 0 1 1 3 S
  • 12. Pseudo Code for Find Find(a) { If S[a] = 0, return a; else Find(S[a]); return; } Complexity? O(N)
  • 13. Pseudo-Code for Union Union(root 1, root 2) { S[root2] = root1; } Complexity? O(1)
  • 14. More Efficient Union Will improve the worst case find complexity to log N When we do a union operation make the smaller tree a subtree of the bigger one Thus the root of the smaller subtree becomes a child of the root of the bigger one. A = {1,2,3} B = {4} Root of B is root of A after union, B is subtree of A Alternatively, union operation can be done by height as well Tree of lesser height is made subtree of the other. We consider only size here.
  • 15. Array storage changes somewhat. If j is a root, S[j] = - size of tree rooted at j If j is not a root, S[j] = parent of j Why is S[j] not equal to the size of tree j, if j is a root? Initially, what is the content of array S? All elements are -1 Size of tree j is an integer, if S[j]=size of tree j and j is root, then it would look like root of j is another element, thus j is not root
  • 16. Pseudo-Code for Union Union(root 1, root 2) { If S[root2] < S[root1], S[root1] = root2; else S[root2]=root1; } Complexity? O(1)
  • 17. Pseudo Code for Find Find(a) { If S[a] < 0, return a; else Find(S[a]); return; }
  • 18. Complexity Analysis for Find Operation If the depth (distance from root) of a node A increases, then the earlier tree consisting the node A becomes a subtree of another. Since only a smaller tree becomes a subtree of another, total size of the combined tree must be at least twice the previous one consisting A. Each time depth of a node increases, the size of the tree increases by at least a factor of 2. At first every node has depth 0
  • 19. Next time depth is 1, tree size is at least 2, depth is 2, tree size is at least 4… depth is k, tree size is at least 2k We know that 2k <= N Thus k <= log N Complexity of Find operation is O(log N) Complexity of any M operations is O(MlogN) Depth of any tree is at most log N
  • 20. Path Compression Makes all operations almost linear in the worst case. Whenever you do Find(j) make S[k]=Find(j) for all elements on the path of j to the root, except the root. All nodes on the path of j now point to the root directly
  • 21. 1 2 3 4 Do Find(5) Find(5) encounters 5, 4 and 3 before reaching root 1 After Find(5): 5 1 2 3 4 5
  • 22. Later Find operations will have lower costs as their depths have been reduced. Any Find operation reduces the cost of future ones.
  • 23. Pseudo Code for New Find Find(a) { If S[a] < 0, return a; else S[a]=Find(S[a]); return; }
  • 24. Complexity Analysis Any M operations take O(Mlog*N) if M is (N) log*N is the number of times we take loglog….logN so as to get a number less than or equal to 1 (log base 2, even otherwise asymptotic order remains the same). log*N grows very slowly with N and is less than 4 or 5 for all practical values of N, log*232 is less than 5 Thus the worst case complexity is linear for all practical purposes.
  • 25. Reading Assignment Chapter 8, till section 8.61. (i.e. section 8.6.1 onwards can be omitted).