SlideShare a Scribd company logo
5
Most read
6
Most read
8
Most read
Sets And Disjoint Sets Union By: Ankita Goyal
Definition Given a  set  of elements, it is often useful to break them up or  partition  them into a number of  separate, nonoverlapping sets . A  disjoint-set data structure  is a  data structure  that keeps track of such a partitioning.
Operation we can perform: A  union-find algorithm  is an algorithm that performs two useful operations on such a data structure: Find : Determine which set a particular element is in. Also useful for determining if two elements are in the same set. Union : Combine or merge two sets into a single set.
Possible representations of sets S1  S2  S3  1 7 8 9 5 2 10 3 4 6
Possible Representations of S1 U S2 1 7 9 8 2 5 10 7 10 2 1 5 9 8 S1 ∪ S2 S1 ∪ S2
Data representation for s1, s2 and s3 1 6 3 5 4 2 10 7 8 9 S1 S2 S3
Array representation of S1, S2 and S3 i [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] p -1 5 -1 3 -1 3 1 1 1 5
Simple algorithms for union and find Algorithm SimpleUnion(i,j) { P[i]:=j; Algorithm SimpleFind(i) { While(p[i]>=0) do i:=p[i]; Return i; }
Weighting rule for 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 i; otherwise make i the parent of j.
Trees obtained using the weighted rule Initial  union(1,2)  union(1,3) Union(1,4)  union(1,n) 1 2 n 3 2 1 5 4 n n 3 2 1 4 n 4 3 2 1 2 n 3 1
Union algorithm with weighting rule Algorithm WeightedUnion(i,j) // Union sets with roots I and j, i != j, using the // weighting rule. p[i]= -count[i] and p[j]= -count[j] { temp:=p[i]+p[j]; if (p[i]>p[j]) then { // i has fewer nodes. p[i]:=j; p[j]:=temp; } else { // j has fewer or equal nodes. P[j]:=i; p[i]:=temp; } }
Thank You

More Related Content

PPT
Divide and conquer
PDF
Algorithm chapter 10
PPTX
Single source Shortest path algorithm with example
PPTX
Type checking in compiler design
PPTX
Disjoint sets union, find
PPTX
9 big o-notation
PPT
Fundamentals of the Analysis of Algorithm Efficiency
PPTX
Quick sort
Divide and conquer
Algorithm chapter 10
Single source Shortest path algorithm with example
Type checking in compiler design
Disjoint sets union, find
9 big o-notation
Fundamentals of the Analysis of Algorithm Efficiency
Quick sort

What's hot (20)

PPTX
Three Address code
PPTX
Stressen's matrix multiplication
PDF
Asymptotic notation
PPTX
sum of subset problem using Backtracking
PPTX
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
PPT
UNIT-1-PPTS-DAA.ppt
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
PPTX
Heap Sort in Design and Analysis of algorithms
PDF
Time and Space Complexity
PPTX
Travelling salesman dynamic programming
PPT
Design and Analysis of Algorithms
PPTX
Dijkstra's Algorithm
PPTX
Lecture optimal binary search tree
PPTX
Distributed concurrency control
PPTX
Merge sort algorithm
PPT
Dinive conquer algorithm
PPTX
Lecture 6 disjoint set
PPTX
ML_ Unit 2_Part_B
PPT
Hashing PPT
Three Address code
Stressen's matrix multiplication
Asymptotic notation
sum of subset problem using Backtracking
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
UNIT-1-PPTS-DAA.ppt
DESIGN AND ANALYSIS OF ALGORITHMS
Heap Sort in Design and Analysis of algorithms
Time and Space Complexity
Travelling salesman dynamic programming
Design and Analysis of Algorithms
Dijkstra's Algorithm
Lecture optimal binary search tree
Distributed concurrency control
Merge sort algorithm
Dinive conquer algorithm
Lecture 6 disjoint set
ML_ Unit 2_Part_B
Hashing PPT
Ad

Viewers also liked (20)

PPTX
Set Operations - Union Find and Bloom Filters
PPT
Disjoint sets
PDF
07. disjoint set
PPTX
Set data structure
PPTX
PPTX
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
PPTX
Set data structure 2
PPTX
Recurrence relationclass 5
PPTX
Big o notation
PDF
01. design & analysis of agorithm intro & complexity analysis
PDF
17 Disjoint Set Representation
PDF
02 Notes Divide and Conquer
PPTX
Algorithm Introduction
PPTX
Algorithm Design and Complexity - Course 1&2
PPT
chapter24.ppt
PDF
Time complexity of union find
PDF
18 Basic Graph Algorithms
PPT
lecture 21
PPTX
Huffman tree
PPTX
Radix 4 FFT algorithm and it time complexity computation
Set Operations - Union Find and Bloom Filters
Disjoint sets
07. disjoint set
Set data structure
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Set data structure 2
Recurrence relationclass 5
Big o notation
01. design & analysis of agorithm intro & complexity analysis
17 Disjoint Set Representation
02 Notes Divide and Conquer
Algorithm Introduction
Algorithm Design and Complexity - Course 1&2
chapter24.ppt
Time complexity of union find
18 Basic Graph Algorithms
lecture 21
Huffman tree
Radix 4 FFT algorithm and it time complexity computation
Ad

Similar to Sets and disjoint sets union123 (20)

PPTX
DISJOINT SETS.pptx
PPT
DAA (Unit-2) (ii).ppt design analysis of algorithms
PDF
learning about union find algorithm lectures
PPTX
Mca ii dfs u-1 introduction to data structure
PPTX
Bca ii dfs u-1 introduction to data structure
PPTX
Path compression
PPTX
Bsc cs ii dfs u-1 introduction to data structure
PPT
computer notes - Data Structures - 29
PPT
ee220s02lec10.ppt.........................
PDF
IRJET- A Survey on Different Searching Algorithms
PDF
Chapter 8 advanced sorting and hashing for print
PDF
A Real Time Application of Soft Set in Parameterization Reduction for Decisio...
PPTX
07+08slide.pptx
PDF
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
PPT
DisjointSetsDisjointSets (1)DisjointSets (1)DisjointSets (1)DisjointSets (1) ...
PPTX
Set relationship, set operation and sigmoid
PDF
A NEW PERSPECTIVE OF PARAMODULATION COMPLEXITY BY SOLVING 100 SLIDING BLOCK P...
PDF
DATA STRUCTURE BY SIVASANKARI
PPTX
SETS IN PYTHON-157755566677778⁵567886676.pptx
PPTX
Introduction-to-Sets-in-Python (Computer).pptx
DISJOINT SETS.pptx
DAA (Unit-2) (ii).ppt design analysis of algorithms
learning about union find algorithm lectures
Mca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
Path compression
Bsc cs ii dfs u-1 introduction to data structure
computer notes - Data Structures - 29
ee220s02lec10.ppt.........................
IRJET- A Survey on Different Searching Algorithms
Chapter 8 advanced sorting and hashing for print
A Real Time Application of Soft Set in Parameterization Reduction for Decisio...
07+08slide.pptx
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
DisjointSetsDisjointSets (1)DisjointSets (1)DisjointSets (1)DisjointSets (1) ...
Set relationship, set operation and sigmoid
A NEW PERSPECTIVE OF PARAMODULATION COMPLEXITY BY SOLVING 100 SLIDING BLOCK P...
DATA STRUCTURE BY SIVASANKARI
SETS IN PYTHON-157755566677778⁵567886676.pptx
Introduction-to-Sets-in-Python (Computer).pptx

Recently uploaded (20)

PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
IGGE1 Understanding the Self1234567891011
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
advance database management system book.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Hazard Identification & Risk Assessment .pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Computing-Curriculum for Schools in Ghana
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
What if we spent less time fighting change, and more time building what’s rig...
IGGE1 Understanding the Self1234567891011
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Final Presentation General Medicine 03-08-2024.pptx
Digestion and Absorption of Carbohydrates, Proteina and Fats
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Paper A Mock Exam 9_ Attempt review.pdf.
advance database management system book.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
History, Philosophy and sociology of education (1).pptx
A systematic review of self-coping strategies used by university students to ...
Hazard Identification & Risk Assessment .pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Computing-Curriculum for Schools in Ghana
Indian roads congress 037 - 2012 Flexible pavement
Orientation - ARALprogram of Deped to the Parents.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx

Sets and disjoint sets union123

  • 1. Sets And Disjoint Sets Union By: Ankita Goyal
  • 2. Definition Given a  set  of elements, it is often useful to break them up or  partition  them into a number of  separate, nonoverlapping sets . A  disjoint-set data structure  is a  data structure  that keeps track of such a partitioning.
  • 3. Operation we can perform: A  union-find algorithm  is an algorithm that performs two useful operations on such a data structure: Find : Determine which set a particular element is in. Also useful for determining if two elements are in the same set. Union : Combine or merge two sets into a single set.
  • 4. Possible representations of sets S1 S2 S3 1 7 8 9 5 2 10 3 4 6
  • 5. Possible Representations of S1 U S2 1 7 9 8 2 5 10 7 10 2 1 5 9 8 S1 ∪ S2 S1 ∪ S2
  • 6. Data representation for s1, s2 and s3 1 6 3 5 4 2 10 7 8 9 S1 S2 S3
  • 7. Array representation of S1, S2 and S3 i [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] p -1 5 -1 3 -1 3 1 1 1 5
  • 8. Simple algorithms for union and find Algorithm SimpleUnion(i,j) { P[i]:=j; Algorithm SimpleFind(i) { While(p[i]>=0) do i:=p[i]; Return i; }
  • 9. Weighting rule for 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 i; otherwise make i the parent of j.
  • 10. Trees obtained using the weighted rule Initial union(1,2) union(1,3) Union(1,4) union(1,n) 1 2 n 3 2 1 5 4 n n 3 2 1 4 n 4 3 2 1 2 n 3 1
  • 11. Union algorithm with weighting rule Algorithm WeightedUnion(i,j) // Union sets with roots I and j, i != j, using the // weighting rule. p[i]= -count[i] and p[j]= -count[j] { temp:=p[i]+p[j]; if (p[i]>p[j]) then { // i has fewer nodes. p[i]:=j; p[j]:=temp; } else { // j has fewer or equal nodes. P[j]:=i; p[i]:=temp; } }