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.
𝑙𝑜𝑔∗
28
= 1 +	 𝑙𝑜𝑔∗
29
= 1
𝑙𝑜𝑔∗
16 = 𝑙𝑜𝑔∗
2;<
= 1 + 𝑙𝑜𝑔∗
2;
= 3
𝑙𝑜𝑔∗
65536 = 𝑙𝑜𝑔∗
2;<<
= 1 + 𝑙𝑜𝑔∗
2;<
= 4
𝑙𝑜𝑔∗2?@@A? = 𝑙𝑜𝑔∗2;<<<
= 1 + 𝑙𝑜𝑔∗2;<<
= 5
𝑙𝑜𝑔∗
4 = 𝑙𝑜𝑔∗
2;
= 1 +	𝑙𝑜𝑔∗
2 = 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 [2B
,2;D
− 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 𝐵⁄ + 	𝑛 2BK8⁄ +	 𝑛 2BK;⁄ + ⋯ +	𝑛 2;D
M8 ≤ 2𝑛 2B	⁄⁄
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)
= ∑ ∑
O
;P
;D
M8
QRB
STU∗
O
8
	≤ 𝑙𝑜𝑔∗
𝑛		 2B
− 1 − 𝐵
O
;D
					≤ 𝑙𝑜𝑔∗ 𝑛	2B 	
O
;D
= 𝑛	𝑙𝑜𝑔∗
𝑛	
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

Tendances (20)

Chapter 3 ds
Chapter 3 dsChapter 3 ds
Chapter 3 ds
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Row major and column major in 2 d
Row major and column major in 2 dRow major and column major in 2 d
Row major and column major in 2 d
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
post119s1-file2
post119s1-file2post119s1-file2
post119s1-file2
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Data structure
Data structureData structure
Data structure
 
Data structures
Data structuresData structures
Data structures
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Set data structure
Set data structure Set data structure
Set data structure
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Answers withexplanations
Answers withexplanationsAnswers withexplanations
Answers withexplanations
 
K mean-clustering algorithm
K mean-clustering algorithmK mean-clustering algorithm
K mean-clustering algorithm
 
Data structure lecture 3
Data structure lecture 3Data structure lecture 3
Data structure lecture 3
 
2-D array
2-D array2-D array
2-D array
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Data structure lecture 4
Data structure lecture 4Data structure lecture 4
Data structure lecture 4
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
 

En vedette

Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union findWei (Terence) Li
 
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
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaAmrinder 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
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 

En vedette (20)

Time complexity of union find
Time complexity of union findTime complexity of union find
Time complexity of union find
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
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 ...
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
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
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 

Similaire à Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zehao Cai, Ishan Sharma)

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
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingzukun
 
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
 
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
 
algorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxalgorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxkassahungebrie
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithmspppepito86
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocksJothi Lakshmi
 
Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Getachew Ganfur
 
IRJET- Commuting Graph of Boundedly Generated Regular Semigroup
IRJET- Commuting Graph of Boundedly Generated Regular SemigroupIRJET- Commuting Graph of Boundedly Generated Regular Semigroup
IRJET- Commuting Graph of Boundedly Generated Regular SemigroupIRJET Journal
 
shell and merge sort
shell and merge sortshell and merge sort
shell and merge sorti i
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
Jurnal informatika
Jurnal informatika Jurnal informatika
Jurnal informatika MamaMa28
 
Skiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queuesSkiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queueszukun
 

Similaire à Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zehao Cai, Ishan Sharma) (20)

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
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
 
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
 
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
 
algorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxalgorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptx
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Shell sort[1]
Shell sort[1]Shell sort[1]
Shell sort[1]
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02
 
simple-sorting algorithms
simple-sorting algorithmssimple-sorting algorithms
simple-sorting algorithms
 
IRJET- Commuting Graph of Boundedly Generated Regular Semigroup
IRJET- Commuting Graph of Boundedly Generated Regular SemigroupIRJET- Commuting Graph of Boundedly Generated Regular Semigroup
IRJET- Commuting Graph of Boundedly Generated Regular Semigroup
 
Sorting
SortingSorting
Sorting
 
Chapter-2.pptx
Chapter-2.pptxChapter-2.pptx
Chapter-2.pptx
 
lecture7.ppt
lecture7.pptlecture7.ppt
lecture7.ppt
 
shell and merge sort
shell and merge sortshell and merge sort
shell and merge sort
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
Jurnal informatika
Jurnal informatika Jurnal informatika
Jurnal informatika
 
C07.heaps
C07.heapsC07.heaps
C07.heaps
 
Skiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queuesSkiena algorithm 2007 lecture07 heapsort priority queues
Skiena algorithm 2007 lecture07 heapsort priority queues
 

Plus de Amrinder Arora

Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsAmrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresAmrinder Arora
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsAmrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackAmrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data StructuresAmrinder Arora
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An IntroductionAmrinder Arora
 

Plus de Amrinder Arora (9)

Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Dernier (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zehao Cai, Ishan Sharma)

  • 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. 𝑙𝑜𝑔∗ 28 = 1 + 𝑙𝑜𝑔∗ 29 = 1 𝑙𝑜𝑔∗ 16 = 𝑙𝑜𝑔∗ 2;< = 1 + 𝑙𝑜𝑔∗ 2; = 3 𝑙𝑜𝑔∗ 65536 = 𝑙𝑜𝑔∗ 2;<< = 1 + 𝑙𝑜𝑔∗ 2;< = 4 𝑙𝑜𝑔∗2?@@A? = 𝑙𝑜𝑔∗2;<<< = 1 + 𝑙𝑜𝑔∗2;<< = 5 𝑙𝑜𝑔∗ 4 = 𝑙𝑜𝑔∗ 2; = 1 + 𝑙𝑜𝑔∗ 2 = 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 [2B ,2;D − 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 𝐵⁄ + 𝑛 2BK8⁄ + 𝑛 2BK;⁄ + ⋯ + 𝑛 2;D M8 ≤ 2𝑛 2B ⁄⁄ 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) = ∑ ∑ O ;P ;D M8 QRB STU∗ O 8 ≤ 𝑙𝑜𝑔∗ 𝑛 2B − 1 − 𝐵 O ;D ≤ 𝑙𝑜𝑔∗ 𝑛 2B O ;D = 𝑛 𝑙𝑜𝑔∗ 𝑛 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