SlideShare a Scribd company logo
Muhammad Tariq Khan
Log(n) Academy
 Topic of Discrete Mathematics
Muhammad Ahmed
 Suppose we have a database of people.
 We want to figure out who is related to whom.
 Initially, we only have a list of people, and information about their relations. For
example “Muhammad is related to Ahmed”.
 Further info: Muhammad is brother of Ahmed. This means that they belongs to
same family. Mathematically they belong to same SET.
Muhammad Ahmed
 If Muhammad is related to Ahmed, and Ahmed is related to Saam, then
Muhammad is related to Saam.
 Once we have relationships information, we would like to answer queries like “Is
Muhammad related to Saam?”
Muhammad SaamAhmed
 A relation R over a set S is called an Equivalence Relation if it has following
properties
1. Reflexivity: for all element x is in set S, x R x
2. Symmetry: for all elements x and y, x R y if and only if y R x
3. Transitivity: for all elements x, y and z, if x R y and y R z then x R z
 The relation “is related to” is an equivalence relation over the set of people.
Muhammad SaamAhmed
 The ≤ relationship is not an equivalence relation.
 It is Reflexive, since x ≤ x,
 and Transitive, since x ≤ y and y ≤ z implies x ≤ z,
 it is Not Symmetric since x ≤ y does not imply y ≤ x.
 Electrical connectivity, where all connections are by metal wires, is an
equivalence relation.
 It is clearly Reflexive, since any component is connected to itself.
 It is Symmetric because if component a is connected to component b then b must
be electrically connected to a.
 It is Transitive, since if component a is connected to component b and b is
connected to c then a is connected to c.
Jack Jamy Omar Osman Ali
Jack
Jamy
Omar
Osman
Ali
Jack Jamy
Omar
Osman
Ali
 What if we have 1000 elements/objects/people
 Will this be efficient in-terms of time, space and memory to create a matrix of
1000 x 1000
 As an example, suppose the equivalence relation is defined over the five-element
set {a1, a2, a3, a4, a5 }.
 There are 25 pairs of elements, each of which is related or not. (30 pairs – 5 self-
pairs=25).
 However, given the information
• a1 R a2,
• a5 R a1,
• a4 R a2,
• a3 R a4,
Implies that all pairs are related.
 We would like to be able to infer this information
quickly.
 Union find operation keeps track of elements which are split into one or more
disjoint set.
 It has 2 primary operation: find and union
Muhammad Tariq Khan
Log(n) Academy
 To apply Union Find, first construct a mapping between your objects and integers
in the range (0, n).
 NOTE: This step is not necessary in general, but it will allow us to construct an
array-based union find which is very efficient and easy to work with.
E FAB D
0 1 2 3 4 5 6 7
H C G
E B A F D H C G
2 0 2 2 6 7 2 0
0 1 2 3 4 5 6 7
 Instructions
 Find(B) = A
 Find(D) = A
 Find(H) = A
 Find(E) = A
Indexes
E FAB D
0 1 2 3 4 5 6 7
H C G
 FIND: To find which component a particular element belongs to, first find the root
of that component by following the parent nodes until a self loop is reached ( a
node who’s parent is its self)
 UNION: To unify 2 elements find which are the root nodes of each component and
if the root nodes are different make one of the root node to be the parent of the
other.
 The input is initially a collection of n sets, each with one element.
 This initial representation is that all relations (except reflexive relations) are
false.
 Each set has a different element so that Si ∩ Sj = null ; this makes the sets
Disjoint.
 Find returns the name of the SET that contains a given element, i.e., Si = find(a)
 Union merges two sets to create a new set Sk = Si U Sj.
 If we want to add the relation a R b, then we first see if a and b are already
related.
 This is done by performing Finds on both a and b to check whether they are in the
same set.
 If they are not, we apply Union which merges the two sets a and b belong to.
 The algorithm to do this is frequently known as Union/Find for this reason.
 Example : Union ( D,G )
 Kruskal’s minimum spanning tree
 Grid percolation
 Network connectivity
 Least Common Ancestor in tree
 Image processing
 Maze Generation
 Typical tree traversal not required, so no need for pointers to children, instead we
need a pointer to parent – an up-tree.
 Union is clearly a constant time operation.
 Running time of find( i ) is proportional to the height of the tree containing node i.
 This can be proportional to n in the worst case (but not always)
 Improvement: Modify Union to ensure that heights stay small.
Get full video course on Udemy.
Course name: Data Structure – Part 2
Link : https://www.udemy.com/logn-data-structure-part2/
For discount coupon : “info@lognacademy.com”

More Related Content

PPTX
Matrix Exponential
PPT
computer notes - Data Structures - 28
PPTX
Data structure
DOCX
GodsMathProject
PPTX
Lecture 6 disjoint set
PDF
Realization of the Relationship between Quantum Mechanics and Relativity
PPT
A17-1 graphing systems
PDF
INDEPENDENT DOMINATION NUMBER OF EULER TOTIENT CAYLEY GRAPHS AND ARITHMETIC G...
Matrix Exponential
computer notes - Data Structures - 28
Data structure
GodsMathProject
Lecture 6 disjoint set
Realization of the Relationship between Quantum Mechanics and Relativity
A17-1 graphing systems
INDEPENDENT DOMINATION NUMBER OF EULER TOTIENT CAYLEY GRAPHS AND ARITHMETIC G...

What's hot (19)

PPT
Sets and disjoint sets union123
DOC
Riemann Hypothesis
PDF
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
PDF
07. disjoint set
PPTX
Riemann Hypothesis and Natural Functions
PDF
New Linear System in Fundamental Physics - Realization of a New Linear System...
PDF
Establishing the Equation of the Wave Function and the System Model (ρ, m, an...
PPTX
Presntation for the post of lecturer in Mathematics
PPT
Solving systems of equations in 3 variables
PDF
Iswc 2016 completeness correctude
PDF
Operations on fourier series
DOCX
Cross product
PPTX
Exponents Rules
PPT
Calc03 9
PDF
Session Notes 2/23/14
PPTX
Laws of exponents and Power
PPTX
10th algebra-lesson 1- part 1
PPTX
Final review flash cards
PPTX
Power of Power Exponent Rule
Sets and disjoint sets union123
Riemann Hypothesis
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
07. disjoint set
Riemann Hypothesis and Natural Functions
New Linear System in Fundamental Physics - Realization of a New Linear System...
Establishing the Equation of the Wave Function and the System Model (ρ, m, an...
Presntation for the post of lecturer in Mathematics
Solving systems of equations in 3 variables
Iswc 2016 completeness correctude
Operations on fourier series
Cross product
Exponents Rules
Calc03 9
Session Notes 2/23/14
Laws of exponents and Power
10th algebra-lesson 1- part 1
Final review flash cards
Power of Power Exponent Rule
Ad

Similar to Disjoint set / Union Find Data Structure (20)

PDF
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
PPTX
Path & application(ds)2
PPTX
data structure
PDF
Graph Matrices and Application: Motivational overview, matrix of graph, relat...
PDF
GRAPH MATRIX APPLICATIONS.pdf
PDF
Relation and it's type Discrete Mathematics.pdf
PDF
Cs229 notes11
PPT
Data matching.ppt
PPTX
relation and operations 204 presentation
PPTX
relation and operations power point presentation
PPTX
relation and operations power point presentation
PPT
computer notes - Data Structures - 27
PPTX
The-Set-theory-presentation-by-students.pptx
PDF
Machine learning (12)
PPT
Section3 1
PDF
Idempotency of Left-Sided Identity on Singular Transformation Semigroup
PPTX
First order logic in artificial Intelligence.pptx
PDF
PDF
Set Properties and Operations in Abstract Algebra
PDF
Lecture 1 - Concept of Sets.pdf
BCA_Semester-II-Discrete Mathematics_unit-ii_Relation and ordering
Path & application(ds)2
data structure
Graph Matrices and Application: Motivational overview, matrix of graph, relat...
GRAPH MATRIX APPLICATIONS.pdf
Relation and it's type Discrete Mathematics.pdf
Cs229 notes11
Data matching.ppt
relation and operations 204 presentation
relation and operations power point presentation
relation and operations power point presentation
computer notes - Data Structures - 27
The-Set-theory-presentation-by-students.pptx
Machine learning (12)
Section3 1
Idempotency of Left-Sided Identity on Singular Transformation Semigroup
First order logic in artificial Intelligence.pptx
Set Properties and Operations in Abstract Algebra
Lecture 1 - Concept of Sets.pdf
Ad

Recently uploaded (20)

PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
master seminar digital applications in india
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Cell Structure & Organelles in detailed.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Classroom Observation Tools for Teachers
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Insiders guide to clinical Medicine.pdf
PDF
RMMM.pdf make it easy to upload and study
Microbial disease of the cardiovascular and lymphatic systems
Sports Quiz easy sports quiz sports quiz
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
master seminar digital applications in india
TR - Agricultural Crops Production NC III.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
Cell Structure & Organelles in detailed.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Classroom Observation Tools for Teachers
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Insiders guide to clinical Medicine.pdf
RMMM.pdf make it easy to upload and study

Disjoint set / Union Find Data Structure

  • 2.  Topic of Discrete Mathematics Muhammad Ahmed
  • 3.  Suppose we have a database of people.  We want to figure out who is related to whom.  Initially, we only have a list of people, and information about their relations. For example “Muhammad is related to Ahmed”.  Further info: Muhammad is brother of Ahmed. This means that they belongs to same family. Mathematically they belong to same SET. Muhammad Ahmed
  • 4.  If Muhammad is related to Ahmed, and Ahmed is related to Saam, then Muhammad is related to Saam.  Once we have relationships information, we would like to answer queries like “Is Muhammad related to Saam?” Muhammad SaamAhmed
  • 5.  A relation R over a set S is called an Equivalence Relation if it has following properties 1. Reflexivity: for all element x is in set S, x R x 2. Symmetry: for all elements x and y, x R y if and only if y R x 3. Transitivity: for all elements x, y and z, if x R y and y R z then x R z  The relation “is related to” is an equivalence relation over the set of people. Muhammad SaamAhmed
  • 6.  The ≤ relationship is not an equivalence relation.  It is Reflexive, since x ≤ x,  and Transitive, since x ≤ y and y ≤ z implies x ≤ z,  it is Not Symmetric since x ≤ y does not imply y ≤ x.
  • 7.  Electrical connectivity, where all connections are by metal wires, is an equivalence relation.  It is clearly Reflexive, since any component is connected to itself.  It is Symmetric because if component a is connected to component b then b must be electrically connected to a.  It is Transitive, since if component a is connected to component b and b is connected to c then a is connected to c.
  • 8. Jack Jamy Omar Osman Ali Jack Jamy Omar Osman Ali Jack Jamy Omar Osman Ali
  • 9.  What if we have 1000 elements/objects/people  Will this be efficient in-terms of time, space and memory to create a matrix of 1000 x 1000
  • 10.  As an example, suppose the equivalence relation is defined over the five-element set {a1, a2, a3, a4, a5 }.  There are 25 pairs of elements, each of which is related or not. (30 pairs – 5 self- pairs=25).
  • 11.  However, given the information • a1 R a2, • a5 R a1, • a4 R a2, • a3 R a4, Implies that all pairs are related.  We would like to be able to infer this information quickly.
  • 12.  Union find operation keeps track of elements which are split into one or more disjoint set.  It has 2 primary operation: find and union
  • 14.  To apply Union Find, first construct a mapping between your objects and integers in the range (0, n).  NOTE: This step is not necessary in general, but it will allow us to construct an array-based union find which is very efficient and easy to work with. E FAB D 0 1 2 3 4 5 6 7 H C G
  • 15. E B A F D H C G 2 0 2 2 6 7 2 0 0 1 2 3 4 5 6 7  Instructions  Find(B) = A  Find(D) = A  Find(H) = A  Find(E) = A Indexes E FAB D 0 1 2 3 4 5 6 7 H C G
  • 16.  FIND: To find which component a particular element belongs to, first find the root of that component by following the parent nodes until a self loop is reached ( a node who’s parent is its self)  UNION: To unify 2 elements find which are the root nodes of each component and if the root nodes are different make one of the root node to be the parent of the other.
  • 17.  The input is initially a collection of n sets, each with one element.  This initial representation is that all relations (except reflexive relations) are false.  Each set has a different element so that Si ∩ Sj = null ; this makes the sets Disjoint.  Find returns the name of the SET that contains a given element, i.e., Si = find(a)  Union merges two sets to create a new set Sk = Si U Sj.
  • 18.  If we want to add the relation a R b, then we first see if a and b are already related.  This is done by performing Finds on both a and b to check whether they are in the same set.  If they are not, we apply Union which merges the two sets a and b belong to.  The algorithm to do this is frequently known as Union/Find for this reason.  Example : Union ( D,G )
  • 19.  Kruskal’s minimum spanning tree  Grid percolation  Network connectivity  Least Common Ancestor in tree  Image processing  Maze Generation
  • 20.  Typical tree traversal not required, so no need for pointers to children, instead we need a pointer to parent – an up-tree.  Union is clearly a constant time operation.  Running time of find( i ) is proportional to the height of the tree containing node i.  This can be proportional to n in the worst case (but not always)  Improvement: Modify Union to ensure that heights stay small.
  • 21. Get full video course on Udemy. Course name: Data Structure – Part 2 Link : https://www.udemy.com/logn-data-structure-part2/ For discount coupon : “info@lognacademy.com”