SlideShare a Scribd company logo
1 of 16
PATH COMPRESSION
Outline
 Background
 Union-Find: Merging Classes of a
Partition
 Union-Find with Copies and Dynamic
Segment Trees
 List Splitting
 Problems on Root-Directed Trees
 Maintaining a Linear Order
Union Whom?
&
Find What?
Background: Disjoint Data
Set
 Disjoint-set data structure is a data
structure that keeps track of a set of
elements partitioned into a number of
disjoint (non-overlapping) subsets.
Disjoint-set data structure is sometimes
called a union-find data structure.
 Union-find algorithm is an algorithm
that performs three useful operations on
such a data structure:
• Find: determine which subset a
particular element is in. This can be used
for determining if two elements are in the
same subset.
• Union: join two subsets into a single
subset.
• Makeset: makes a set containing only a
given element (a singleton).
Background: Set as Tree
 S = {2, 4, 5, 9, 11, 13, 30}
 Some possible tree representations
4
2 9 11 30 5 13
Root-Directed Trees
• Union-Find structure can be
represented by trees with parent
pointers.
Representative= 13
4
2
9
30
5
13
11
1
Union Operation
 Union(i,j) : i and j are the roots of two
different trees, i != j.
 To unite the trees, make one tree a
subtree of the other.
 Time Complexity of Union operation is
O(1)
Smart Union Approaches
There are two approaches to apply union
operation:
 Union by Height
 Union by Weight
Union by Height
Background: Union by Height
Union(7,13)=13
4
2
9
30
5
13
11
1
7
8 3 22 6
10
20 16 14 12
Height = 4
Height = 3
Union by Weight
 The tree with fewer number of elements
becomes subtree of the other tree.
4
2
9
30
5
13
11
1
7
8 3 22 6
10
20 16 14 12
Weight = 10
Weight = 8
Union(7,13)=7
Applications
There are many applications that utilize
this structure. Some of them are:
 Check the network connectivity.
 Kruskal's minimum spanning tree
algorithm.
 Find least common ancestor.
Union by Rank & Path
Compression
 Union by Rank: Each node is associated
with a rank, which is the upper bound on
the height of the node (i.e., the height of
subtree rooted at the node), then when
UNION, let the root with smaller rank
point to the root with larger rank.
 Path Compression: used in FIND-
SET(x) operation, make each node in
the path from x to the root directly point
to the root. Thus reduce the tree height.
Analysis of Union by Rank
with Path Compression
 Discuss the following:
 A very quickly growing function and its
very slowly growing inverse
 Properties of Ranks
 Proving time bound of O(m(n))
where (n) is a very slowly growing
function.
 For integers k0 and j 1, define Ak(j):
 Ak(j)= j+1 if k=0
 Ak-1
(j+1)(j) if k1
 Where Ak-1
0(j)=j, Ak-1
(i)(j)= Ak-1(Ak-1
(i-1)(j)) for i
1.
 k is called the level of the function and
 i in the above is called iterations.
 Ak(j) strictly increase with both j and k.
 Let us see how quick the increase is!!
Summary
 Disjoint set
 Three operations
 Different implementations and different
costs
 Forest implementation:
 Union by rank and path compression
 Properties: rank, level, iter.
 Amortized analysis of the operations:
Potential function.

More Related Content

What's hot

What's hot (20)

M ary-tree
M ary-treeM ary-tree
M ary-tree
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Stack application
Stack applicationStack application
Stack application
 
Logic gate
Logic gateLogic gate
Logic gate
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 
Heap sort
Heap sortHeap sort
Heap sort
 
Basic Logic gates
Basic Logic gatesBasic Logic gates
Basic Logic gates
 
B tree
B treeB tree
B tree
 
8086 pin diagram description
8086 pin diagram description8086 pin diagram description
8086 pin diagram description
 
Beta gamma functions
Beta gamma functionsBeta gamma functions
Beta gamma functions
 
B trees and_b__trees
B trees and_b__treesB trees and_b__trees
B trees and_b__trees
 
Switching
SwitchingSwitching
Switching
 
Electronic dice
Electronic diceElectronic dice
Electronic dice
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
Ebcdic code 24 1
Ebcdic code 24 1Ebcdic code 24 1
Ebcdic code 24 1
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
 
A Short Study of Galois Field
A Short Study of Galois FieldA Short Study of Galois Field
A Short Study of Galois Field
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 

Similar to Path compression

Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint setAbirami A
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversalIntro C# Book
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersAmrinder Arora
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
An Optimal Approach For Knowledge Protection In Structured Frequent Patterns
An Optimal Approach For Knowledge Protection In Structured Frequent PatternsAn Optimal Approach For Knowledge Protection In Structured Frequent Patterns
An Optimal Approach For Knowledge Protection In Structured Frequent PatternsWaqas Tariq
 
«Дизайн продвинутых нереляционных схем для Big Data»
«Дизайн продвинутых нереляционных схем для Big Data»«Дизайн продвинутых нереляционных схем для Big Data»
«Дизайн продвинутых нереляционных схем для Big Data»Olga Lavrentieva
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like StructuresIntro C# Book
 
Higher-order clustering coefficients at Purdue CSoI
Higher-order clustering coefficients at Purdue CSoIHigher-order clustering coefficients at Purdue CSoI
Higher-order clustering coefficients at Purdue CSoIAustin Benson
 
Machine Learning Algorithms (Part 1)
Machine Learning Algorithms (Part 1)Machine Learning Algorithms (Part 1)
Machine Learning Algorithms (Part 1)Zihui Li
 
datastructureppt-190327174340 (1).pptx
datastructureppt-190327174340 (1).pptxdatastructureppt-190327174340 (1).pptx
datastructureppt-190327174340 (1).pptxAsthaChaurasia4
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123Ankita Goyal
 
Matrix Factorization In Recommender Systems
Matrix Factorization In Recommender SystemsMatrix Factorization In Recommender Systems
Matrix Factorization In Recommender SystemsYONG ZHENG
 

Similar to Path compression (20)

DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MST
 
Disjoint set
Disjoint setDisjoint set
Disjoint set
 
Lecture 6 disjoint set
Lecture 6 disjoint setLecture 6 disjoint set
Lecture 6 disjoint set
 
17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal17. Java data structures trees representation and traversal
17. Java data structures trees representation and traversal
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
An Optimal Approach For Knowledge Protection In Structured Frequent Patterns
An Optimal Approach For Knowledge Protection In Structured Frequent PatternsAn Optimal Approach For Knowledge Protection In Structured Frequent Patterns
An Optimal Approach For Knowledge Protection In Structured Frequent Patterns
 
«Дизайн продвинутых нереляционных схем для Big Data»
«Дизайн продвинутых нереляционных схем для Big Data»«Дизайн продвинутых нереляционных схем для Big Data»
«Дизайн продвинутых нереляционных схем для Big Data»
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
 
Higher-order clustering coefficients at Purdue CSoI
Higher-order clustering coefficients at Purdue CSoIHigher-order clustering coefficients at Purdue CSoI
Higher-order clustering coefficients at Purdue CSoI
 
Machine Learning Algorithms (Part 1)
Machine Learning Algorithms (Part 1)Machine Learning Algorithms (Part 1)
Machine Learning Algorithms (Part 1)
 
datastructureppt-190327174340 (1).pptx
datastructureppt-190327174340 (1).pptxdatastructureppt-190327174340 (1).pptx
datastructureppt-190327174340 (1).pptx
 
Disjoint sets union, find
Disjoint sets  union, findDisjoint sets  union, find
Disjoint sets union, find
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
M tree
M treeM tree
M tree
 
Persistent Search Trees
Persistent Search TreesPersistent Search Trees
Persistent Search Trees
 
Matrix Factorization In Recommender Systems
Matrix Factorization In Recommender SystemsMatrix Factorization In Recommender Systems
Matrix Factorization In Recommender Systems
 
Implementation of union
Implementation of unionImplementation of union
Implementation of union
 

More from DEEPIKA T

71619109 configuration-management.pdf (1) (1)
71619109 configuration-management.pdf (1) (1)71619109 configuration-management.pdf (1) (1)
71619109 configuration-management.pdf (1) (1)DEEPIKA T
 
Parallelizing matrix multiplication
Parallelizing  matrix multiplicationParallelizing  matrix multiplication
Parallelizing matrix multiplicationDEEPIKA T
 
Health care in big data analytics
Health care in big data analyticsHealth care in big data analytics
Health care in big data analyticsDEEPIKA T
 
Role of human interaction
Role of human interactionRole of human interaction
Role of human interactionDEEPIKA T
 
Basic analtyics & advanced analtyics
Basic analtyics & advanced analtyicsBasic analtyics & advanced analtyics
Basic analtyics & advanced analtyicsDEEPIKA T
 
Soap,Rest&Json
Soap,Rest&JsonSoap,Rest&Json
Soap,Rest&JsonDEEPIKA T
 
Remote method invocation
Remote  method invocationRemote  method invocation
Remote method invocationDEEPIKA T
 
Graph representation
Graph representationGraph representation
Graph representationDEEPIKA T
 
Presentation2
Presentation2Presentation2
Presentation2DEEPIKA T
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]DEEPIKA T
 
Topological sort
Topological sortTopological sort
Topological sortDEEPIKA T
 

More from DEEPIKA T (20)

See
SeeSee
See
 
71619109 configuration-management.pdf (1) (1)
71619109 configuration-management.pdf (1) (1)71619109 configuration-management.pdf (1) (1)
71619109 configuration-management.pdf (1) (1)
 
80068
8006880068
80068
 
242296
242296242296
242296
 
Data mining
Data miningData mining
Data mining
 
Parallelizing matrix multiplication
Parallelizing  matrix multiplicationParallelizing  matrix multiplication
Parallelizing matrix multiplication
 
Health care in big data analytics
Health care in big data analyticsHealth care in big data analytics
Health care in big data analytics
 
Ajax
AjaxAjax
Ajax
 
Role of human interaction
Role of human interactionRole of human interaction
Role of human interaction
 
Basic analtyics & advanced analtyics
Basic analtyics & advanced analtyicsBasic analtyics & advanced analtyics
Basic analtyics & advanced analtyics
 
Soap,Rest&Json
Soap,Rest&JsonSoap,Rest&Json
Soap,Rest&Json
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Jdbc ja
Jdbc jaJdbc ja
Jdbc ja
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Remote method invocation
Remote  method invocationRemote  method invocation
Remote method invocation
 
Graph representation
Graph representationGraph representation
Graph representation
 
Al
AlAl
Al
 
Presentation2
Presentation2Presentation2
Presentation2
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Topological sort
Topological sortTopological sort
Topological sort
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 

Path compression

  • 2. Outline  Background  Union-Find: Merging Classes of a Partition  Union-Find with Copies and Dynamic Segment Trees  List Splitting  Problems on Root-Directed Trees  Maintaining a Linear Order
  • 4. Background: Disjoint Data Set  Disjoint-set data structure is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. Disjoint-set data structure is sometimes called a union-find data structure.
  • 5.  Union-find algorithm is an algorithm that performs three useful operations on such a data structure: • Find: determine which subset a particular element is in. This can be used for determining if two elements are in the same subset. • Union: join two subsets into a single subset. • Makeset: makes a set containing only a given element (a singleton).
  • 6. Background: Set as Tree  S = {2, 4, 5, 9, 11, 13, 30}  Some possible tree representations 4 2 9 11 30 5 13
  • 7. Root-Directed Trees • Union-Find structure can be represented by trees with parent pointers. Representative= 13 4 2 9 30 5 13 11 1
  • 8. Union Operation  Union(i,j) : i and j are the roots of two different trees, i != j.  To unite the trees, make one tree a subtree of the other.  Time Complexity of Union operation is O(1)
  • 9. Smart Union Approaches There are two approaches to apply union operation:  Union by Height  Union by Weight
  • 10. Union by Height Background: Union by Height Union(7,13)=13 4 2 9 30 5 13 11 1 7 8 3 22 6 10 20 16 14 12 Height = 4 Height = 3
  • 11. Union by Weight  The tree with fewer number of elements becomes subtree of the other tree. 4 2 9 30 5 13 11 1 7 8 3 22 6 10 20 16 14 12 Weight = 10 Weight = 8 Union(7,13)=7
  • 12. Applications There are many applications that utilize this structure. Some of them are:  Check the network connectivity.  Kruskal's minimum spanning tree algorithm.  Find least common ancestor.
  • 13. Union by Rank & Path Compression  Union by Rank: Each node is associated with a rank, which is the upper bound on the height of the node (i.e., the height of subtree rooted at the node), then when UNION, let the root with smaller rank point to the root with larger rank.  Path Compression: used in FIND- SET(x) operation, make each node in the path from x to the root directly point to the root. Thus reduce the tree height.
  • 14. Analysis of Union by Rank with Path Compression  Discuss the following:  A very quickly growing function and its very slowly growing inverse  Properties of Ranks  Proving time bound of O(m(n)) where (n) is a very slowly growing function.
  • 15.  For integers k0 and j 1, define Ak(j):  Ak(j)= j+1 if k=0  Ak-1 (j+1)(j) if k1  Where Ak-1 0(j)=j, Ak-1 (i)(j)= Ak-1(Ak-1 (i-1)(j)) for i 1.  k is called the level of the function and  i in the above is called iterations.  Ak(j) strictly increase with both j and k.  Let us see how quick the increase is!!
  • 16. Summary  Disjoint set  Three operations  Different implementations and different costs  Forest implementation:  Union by rank and path compression  Properties: rank, level, iter.  Amortized analysis of the operations: Potential function.