SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Dec. 09, 2015
Wei Li
Zehao Cai
Ishan Sharma
Time Complexity of Union Find
1Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Algorithm Definition
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.
Union find algorithm
supports three operations on a set of elements:
• MAKE-SET(x). Create a new set containing only element x.
• FIND(x). Return a canonical element in the set containing x.
• UNION(x, y). Merge the sets containing x and y.
Implementation: Linked-list, Tree(Often)
2Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Find(b) = c | Find(d) = f | Find(b) = f
b → h → c | d → f | b → h → c → f
Quick-find & Quick-union
3Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Definition: The rank of a node x is similar to the height of x.
When performing the operation Union(x, y), we compare rank(x) and
rank(y):
• If rank(x) < rank(y), make y the parent of x.
• If rank(x) > rank(y), make x the parent of y.
• If rank(x) = rank(y), make y the parent of x and increase the rank of
y by one.
First Optimization: Union By Rank Heuristic
4Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Note. In this case, rank = height.
During the execution of Find(e), e and all intermediate vertices on
the path from e to the root are made children of the root x.
Second Optimization: Path Compression
5Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
6Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Union by Rank & Path Compression
This is why we call it “union by rank” rather than “union by height”.
Algorithms Worst-case time
Quick-find 𝑚𝑛
Quick-union 𝑚𝑛
QU + Union by Rank 𝑛 + 𝑚𝑙𝑜𝑔𝑛
QU + Path compression 𝑛 + 𝑚𝑙𝑜𝑔𝑛
QU + Union by rank + Path compression 𝒏 + 𝒎𝒍𝒐𝒈∗
𝒏
m union-find operations on a set of n objects.
Time Complexity
7Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Lemma 1: as the find function follows the path along to
the root, the rank of node it encounters is increasing.
Union: a tree with smaller rank will be attached to a tree with greater
rank, rather than vice versa.
Find: all nodes visited along the path will be attached to the root,
which has larger rank than its children.
8Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Lemma 2: A node u which is root of a sub-tree with
rank r has at least 2r nodes.
Proof: Initially when each node is the root of its own tree, it's trivially true.
Assume that a node u with rank r has at least 2r nodes. Then when two
tree with rank r Unions by Rank and form a tree with rank r + 1, the new
node has at least 2r + 2r = 2r + 1 nodes.
9Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Lemma 3: The maximum number of nodes of rank r is
at most n/2r.
Proof: From lemma 2, we know that a node u which is root of a sub-tree
with rank r has at least 2r nodes. We will get the maximum number of nodes
of rank r when each node with rank r is the root of a tree that has exactly 2r
nodes. In this case, the number of nodes of rank r is n / 2r
10Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
We define “bucket” here: a bucket is a set that contains vertices with
particular ranks.
Proof
11Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
𝒍𝒐𝒈∗ 𝒏
𝑙𝑜𝑔∗
𝑛 ∶= /
0																																					𝑖𝑓	𝑛 ≤ 1
1 + 𝑙𝑜𝑔∗
𝑙𝑜𝑔𝑛 										𝑖𝑓	𝑛 > 1
Definition: For all non-negative integer n, 𝑙𝑜𝑔∗
𝑛	is defined as
We have 𝑙𝑜𝑔∗
𝑛 ≤ 5	 unless n exceeds the atoms in the universe.
𝑙𝑜𝑔∗
29
= 1 +	 𝑙𝑜𝑔∗
2:
= 1
𝑙𝑜𝑔∗
16 = 𝑙𝑜𝑔∗
2<=
= 1 + 𝑙𝑜𝑔∗
2<
= 3
𝑙𝑜𝑔∗
65536 = 𝑙𝑜𝑔∗
2<==
= 1 + 𝑙𝑜𝑔∗
2<=
= 4
𝑙𝑜𝑔∗2@AAB@ = 𝑙𝑜𝑔∗2<===
= 1 + 𝑙𝑜𝑔∗2<==
= 5
𝑙𝑜𝑔∗
4 = 𝑙𝑜𝑔∗
2<
= 1 +	𝑙𝑜𝑔∗
29
= 2
12Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
We can make two observations about the buckets.
The total number of buckets is at most 𝒍𝒐𝒈∗ 𝒏.
Proof: When we go from one bucket to the next, we add one more two
to the power, that is, the next bucket to [B, 2B − 1] will be [2C
,2<E
− 1 ]
The maximum number of elements in bucket [B, 2B – 1] is at
most 𝒏.
Proof: The maximum number of elements in bucket [B, 2B – 1] is at
most 𝑛 2 𝐵⁄ +	 𝑛 2CI9⁄ + 	 𝑛 2CI<⁄ + ⋯ +	 𝑛 2<EK9
≤ 2 𝐵 − 1 − 𝐵 ∗ 𝑛/2 𝐵⁄ ≤ n
Proof
13Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Let F represent the list of "find" operations performed, and let
Then the total cost of m finds is T = T1 + T2 + T3
Proof
14Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Proof
15Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
T1 = constant time cost (1) per m operations: O(m)
T2 = maximum number of different buckets: O(𝑚	𝑙𝑜𝑔∗
𝑛)
T3 = for all buckets ( for all notes in one bucket)
= ∑ ∑
N
<O
<E
K9
PQC
RST∗
N
9
	≤ 𝑙𝑜𝑔∗
𝑛		 2C
− 1 − 𝐵
N
<E
					≤ 𝑙𝑜𝑔∗ 𝑛	2C 	
N
<E
= 𝑛	𝑙𝑜𝑔∗
𝑛	
Proof
T = T1 + T2 + T3 = O(m) + O(𝑚𝑙𝑜𝑔∗
𝑛) + O(𝑛𝑙𝑜𝑔∗
𝑛)
𝑚 ≥ 𝑛 → O(𝒎𝒍𝒐𝒈∗
𝒏)
16Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Algorithms Worst-case time
Quick-find 𝑚𝑛
Quick-union 𝑚𝑛
QU + Union by Rank 𝑛 + 𝑚𝑙𝑜𝑔𝑛
QU + Path compression 𝑛 + 𝑚𝑙𝑜𝑔𝑛
QU + Union by rank + Path compression 𝒏 + 𝒎𝒍𝒐𝒈∗
𝒏
m union-find operations on a set of n objects.
Time Complexity
17Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
Algorithm & Time Complexity
• Simple data structure, algorithm easy to implement.
• Complex to prove time complexity. (Proved in 1975, Tarjan,
Robert Endre )
• Time complexity is near linear.
Applications
• Keep track of the connected components of an undirected
graph;
• Find minimum spanning tree of a graph.
Conclusions
18Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
https://en.wikipedia.org/wiki/Disjoint-set_data_structure
https://en.wikipedia.org/wiki/Proof_of_O(log*n)_time_complexity_of_u
nion%E2%80%93find
http://www.ccse.kfupm.edu.sa/~wasfi/Resources/ICS353CD/Lecture1
7/lec17_slide01.swf
http://sarielhp.org/teach/2004/b/webpage/lec/22_uf.pdf
https://www.cs.princeton.edu/courses/archive/spring13/cos423/lecture
s/UnionFind.pdf
References
19Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015

Contenu connexe

Tendances

コンピュータシステムの理論と実装1
コンピュータシステムの理論と実装1コンピュータシステムの理論と実装1
コンピュータシステムの理論と実装1H T
 
Serie recurrents & arithmetiques
Serie recurrents & arithmetiquesSerie recurrents & arithmetiques
Serie recurrents & arithmetiquesmohamed_SAYARI
 
Chapitre 4 récursivité
Chapitre 4 récursivitéChapitre 4 récursivité
Chapitre 4 récursivitéSana Aroussi
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notationMuthiah Abbhirami
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Perceptron monocouche en français
Perceptron monocouche en françaisPerceptron monocouche en français
Perceptron monocouche en françaisHakim Nasaoui
 
Construire un moteur d'inférence
Construire un moteur d'inférenceConstruire un moteur d'inférence
Construire un moteur d'inférenceJean Rohmer
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAbhishek L.R
 
Exercices_Python_Fenni_2023 -corrigé.pdf
Exercices_Python_Fenni_2023 -corrigé.pdfExercices_Python_Fenni_2023 -corrigé.pdf
Exercices_Python_Fenni_2023 -corrigé.pdfsalah fenni
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked listRoshan Chaudhary
 
Algorithmes d'approximation
Algorithmes d'approximationAlgorithmes d'approximation
Algorithmes d'approximationmohamed_SAYARI
 

Tendances (20)

コンピュータシステムの理論と実装1
コンピュータシステムの理論と実装1コンピュータシステムの理論と実装1
コンピュータシステムの理論と実装1
 
1s and 2s complement
1s and 2s complement1s and 2s complement
1s and 2s complement
 
Linked list
Linked listLinked list
Linked list
 
Recursion
RecursionRecursion
Recursion
 
Serie recurrents & arithmetiques
Serie recurrents & arithmetiquesSerie recurrents & arithmetiques
Serie recurrents & arithmetiques
 
Chapitre 4 récursivité
Chapitre 4 récursivitéChapitre 4 récursivité
Chapitre 4 récursivité
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Perceptron monocouche en français
Perceptron monocouche en françaisPerceptron monocouche en français
Perceptron monocouche en français
 
Construire un moteur d'inférence
Construire un moteur d'inférenceConstruire un moteur d'inférence
Construire un moteur d'inférence
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Exercices_Python_Fenni_2023 -corrigé.pdf
Exercices_Python_Fenni_2023 -corrigé.pdfExercices_Python_Fenni_2023 -corrigé.pdf
Exercices_Python_Fenni_2023 -corrigé.pdf
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
 
KMAP
KMAPKMAP
KMAP
 
Convex hulls & Chan's algorithm
Convex hulls & Chan's algorithmConvex hulls & Chan's algorithm
Convex hulls & Chan's algorithm
 
Lec1
Lec1Lec1
Lec1
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
 
Algorithmes d'approximation
Algorithmes d'approximationAlgorithmes d'approximation
Algorithmes d'approximation
 

En vedette

Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Amrinder Arora
 
Challenges of Agile Software Development
Challenges of Agile Software DevelopmentChallenges of Agile Software Development
Challenges of Agile Software DevelopmentWei (Terence) Li
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2Tech_MX
 
Distributed Development Best Practices
Distributed Development Best PracticesDistributed Development Best Practices
Distributed Development Best PracticesSunil Mundra
 
Agile Best Practices For Distributed Development
Agile Best Practices For Distributed DevelopmentAgile Best Practices For Distributed Development
Agile Best Practices For Distributed DevelopmentSunil Mundra
 
Ben Reich - Continuous Integration Best Practices in Agile Environments
Ben Reich - Continuous Integration Best Practices in Agile EnvironmentsBen Reich - Continuous Integration Best Practices in Agile Environments
Ben Reich - Continuous Integration Best Practices in Agile EnvironmentsAgileSparks
 
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.Andrea Angella
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsAmrinder Arora
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123Ankita Goyal
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisAmrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine LearningAmrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 

En vedette (20)

Algorithms, Union Find
Algorithms, Union FindAlgorithms, Union Find
Algorithms, Union Find
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Challenges of Agile Software Development
Challenges of Agile Software DevelopmentChallenges of Agile Software Development
Challenges of Agile Software Development
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Distributed Development Best Practices
Distributed Development Best PracticesDistributed Development Best Practices
Distributed Development Best Practices
 
Agile Best Practices For Distributed Development
Agile Best Practices For Distributed DevelopmentAgile Best Practices For Distributed Development
Agile Best Practices For Distributed Development
 
Ben Reich - Continuous Integration Best Practices in Agile Environments
Ben Reich - Continuous Integration Best Practices in Agile EnvironmentsBen Reich - Continuous Integration Best Practices in Agile Environments
Ben Reich - Continuous Integration Best Practices in Agile Environments
 
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
 
07. disjoint set
07. disjoint set07. disjoint set
07. disjoint set
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
NP completeness
NP completenessNP completeness
NP completeness
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 

Similaire à Time complexity of union find

Review session2
Review session2Review session2
Review session2NEEDY12345
 
03-data-structures.pdf
03-data-structures.pdf03-data-structures.pdf
03-data-structures.pdfNash229987
 
MLSD18. Unsupervised Learning
MLSD18. Unsupervised LearningMLSD18. Unsupervised Learning
MLSD18. Unsupervised LearningBigML, Inc
 
Algo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptAlgo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptHebaSamy22
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingzukun
 
Path compression
Path compressionPath compression
Path compressionDEEPIKA T
 
Enhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial DatasetEnhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial DatasetAlaaZ
 
algorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxalgorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxkassahungebrie
 
Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Getachew Ganfur
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
Top school in noida
Top school in noidaTop school in noida
Top school in noidaEdhole.com
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocksJothi Lakshmi
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
Heap
HeapHeap
HeapArun
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfShiwani Gupta
 
segment tree algorithm.pptx
segment tree algorithm.pptxsegment tree algorithm.pptx
segment tree algorithm.pptxMuzamil Amin
 
Jurnal informatika
Jurnal informatika Jurnal informatika
Jurnal informatika MamaMa28
 

Similaire à Time complexity of union find (20)

Review session2
Review session2Review session2
Review session2
 
03-data-structures.pdf
03-data-structures.pdf03-data-structures.pdf
03-data-structures.pdf
 
MLSD18. Unsupervised Learning
MLSD18. Unsupervised LearningMLSD18. Unsupervised Learning
MLSD18. Unsupervised Learning
 
Algo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptAlgo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.ppt
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
 
Path compression
Path compressionPath compression
Path compression
 
Enhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial DatasetEnhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial Dataset
 
algorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxalgorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptx
 
Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Top school in noida
Top school in noidaTop school in noida
Top school in noida
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
Heap
HeapHeap
Heap
 
Scapegoat Tree
Scapegoat TreeScapegoat Tree
Scapegoat Tree
 
module2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdfmodule2_dIVIDEncONQUER_2022.pdf
module2_dIVIDEncONQUER_2022.pdf
 
Shell sort[1]
Shell sort[1]Shell sort[1]
Shell sort[1]
 
segment tree algorithm.pptx
segment tree algorithm.pptxsegment tree algorithm.pptx
segment tree algorithm.pptx
 
lecture7.ppt
lecture7.pptlecture7.ppt
lecture7.ppt
 
Jurnal informatika
Jurnal informatika Jurnal informatika
Jurnal informatika
 

Dernier

UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainAbdul Ahad
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 

Dernier (20)

UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software Domain
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 

Time complexity of union find

  • 1. Dec. 09, 2015 Wei Li Zehao Cai Ishan Sharma Time Complexity of Union Find 1Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 2. Algorithm Definition 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. Union find algorithm supports three operations on a set of elements: • MAKE-SET(x). Create a new set containing only element x. • FIND(x). Return a canonical element in the set containing x. • UNION(x, y). Merge the sets containing x and y. Implementation: Linked-list, Tree(Often) 2Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 3. Find(b) = c | Find(d) = f | Find(b) = f b → h → c | d → f | b → h → c → f Quick-find & Quick-union 3Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 4. Definition: The rank of a node x is similar to the height of x. When performing the operation Union(x, y), we compare rank(x) and rank(y): • If rank(x) < rank(y), make y the parent of x. • If rank(x) > rank(y), make x the parent of y. • If rank(x) = rank(y), make y the parent of x and increase the rank of y by one. First Optimization: Union By Rank Heuristic 4Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015 Note. In this case, rank = height.
  • 5. During the execution of Find(e), e and all intermediate vertices on the path from e to the root are made children of the root x. Second Optimization: Path Compression 5Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 6. 6Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015 Union by Rank & Path Compression This is why we call it “union by rank” rather than “union by height”.
  • 7. Algorithms Worst-case time Quick-find 𝑚𝑛 Quick-union 𝑚𝑛 QU + Union by Rank 𝑛 + 𝑚𝑙𝑜𝑔𝑛 QU + Path compression 𝑛 + 𝑚𝑙𝑜𝑔𝑛 QU + Union by rank + Path compression 𝒏 + 𝒎𝒍𝒐𝒈∗ 𝒏 m union-find operations on a set of n objects. Time Complexity 7Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 8. Lemma 1: as the find function follows the path along to the root, the rank of node it encounters is increasing. Union: a tree with smaller rank will be attached to a tree with greater rank, rather than vice versa. Find: all nodes visited along the path will be attached to the root, which has larger rank than its children. 8Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 9. Lemma 2: A node u which is root of a sub-tree with rank r has at least 2r nodes. Proof: Initially when each node is the root of its own tree, it's trivially true. Assume that a node u with rank r has at least 2r nodes. Then when two tree with rank r Unions by Rank and form a tree with rank r + 1, the new node has at least 2r + 2r = 2r + 1 nodes. 9Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 10. Lemma 3: The maximum number of nodes of rank r is at most n/2r. Proof: From lemma 2, we know that a node u which is root of a sub-tree with rank r has at least 2r nodes. We will get the maximum number of nodes of rank r when each node with rank r is the root of a tree that has exactly 2r nodes. In this case, the number of nodes of rank r is n / 2r 10Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 11. We define “bucket” here: a bucket is a set that contains vertices with particular ranks. Proof 11Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 12. 𝒍𝒐𝒈∗ 𝒏 𝑙𝑜𝑔∗ 𝑛 ∶= / 0 𝑖𝑓 𝑛 ≤ 1 1 + 𝑙𝑜𝑔∗ 𝑙𝑜𝑔𝑛 𝑖𝑓 𝑛 > 1 Definition: For all non-negative integer n, 𝑙𝑜𝑔∗ 𝑛 is defined as We have 𝑙𝑜𝑔∗ 𝑛 ≤ 5 unless n exceeds the atoms in the universe. 𝑙𝑜𝑔∗ 29 = 1 + 𝑙𝑜𝑔∗ 2: = 1 𝑙𝑜𝑔∗ 16 = 𝑙𝑜𝑔∗ 2<= = 1 + 𝑙𝑜𝑔∗ 2< = 3 𝑙𝑜𝑔∗ 65536 = 𝑙𝑜𝑔∗ 2<== = 1 + 𝑙𝑜𝑔∗ 2<= = 4 𝑙𝑜𝑔∗2@AAB@ = 𝑙𝑜𝑔∗2<=== = 1 + 𝑙𝑜𝑔∗2<== = 5 𝑙𝑜𝑔∗ 4 = 𝑙𝑜𝑔∗ 2< = 1 + 𝑙𝑜𝑔∗ 29 = 2 12Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 13. We can make two observations about the buckets. The total number of buckets is at most 𝒍𝒐𝒈∗ 𝒏. Proof: When we go from one bucket to the next, we add one more two to the power, that is, the next bucket to [B, 2B − 1] will be [2C ,2<E − 1 ] The maximum number of elements in bucket [B, 2B – 1] is at most 𝒏. Proof: The maximum number of elements in bucket [B, 2B – 1] is at most 𝑛 2 𝐵⁄ + 𝑛 2CI9⁄ + 𝑛 2CI<⁄ + ⋯ + 𝑛 2<EK9 ≤ 2 𝐵 − 1 − 𝐵 ∗ 𝑛/2 𝐵⁄ ≤ n Proof 13Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 14. Let F represent the list of "find" operations performed, and let Then the total cost of m finds is T = T1 + T2 + T3 Proof 14Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 16. T1 = constant time cost (1) per m operations: O(m) T2 = maximum number of different buckets: O(𝑚 𝑙𝑜𝑔∗ 𝑛) T3 = for all buckets ( for all notes in one bucket) = ∑ ∑ N <O <E K9 PQC RST∗ N 9 ≤ 𝑙𝑜𝑔∗ 𝑛 2C − 1 − 𝐵 N <E ≤ 𝑙𝑜𝑔∗ 𝑛 2C N <E = 𝑛 𝑙𝑜𝑔∗ 𝑛 Proof T = T1 + T2 + T3 = O(m) + O(𝑚𝑙𝑜𝑔∗ 𝑛) + O(𝑛𝑙𝑜𝑔∗ 𝑛) 𝑚 ≥ 𝑛 → O(𝒎𝒍𝒐𝒈∗ 𝒏) 16Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 17. Algorithms Worst-case time Quick-find 𝑚𝑛 Quick-union 𝑚𝑛 QU + Union by Rank 𝑛 + 𝑚𝑙𝑜𝑔𝑛 QU + Path compression 𝑛 + 𝑚𝑙𝑜𝑔𝑛 QU + Union by rank + Path compression 𝒏 + 𝒎𝒍𝒐𝒈∗ 𝒏 m union-find operations on a set of n objects. Time Complexity 17Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015
  • 18. Algorithm & Time Complexity • Simple data structure, algorithm easy to implement. • Complex to prove time complexity. (Proved in 1975, Tarjan, Robert Endre ) • Time complexity is near linear. Applications • Keep track of the connected components of an undirected graph; • Find minimum spanning tree of a graph. Conclusions 18Wei/Zehao/Ishan CSCI 6212/Arora/Fall 2015