SlideShare a Scribd company logo
2
Most read
4
Most read
7
Most read
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

More Related Content

PPT
Merge sort
saranyatdr
 
PPTX
Red black trees
mumairsadiq
 
PPT
Heaps
Hafiz Atif Amin
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
PPTX
Quick sort
Jehat Hassan
 
PPT
Asymptotic notations
Ehtisham Ali
 
PPTX
Solving recurrences
Megha V
 
PPT
Binary search tree(bst)
Hossain Md Shakhawat
 
Merge sort
saranyatdr
 
Red black trees
mumairsadiq
 
heap Sort Algorithm
Lemia Algmri
 
Quick sort
Jehat Hassan
 
Asymptotic notations
Ehtisham Ali
 
Solving recurrences
Megha V
 
Binary search tree(bst)
Hossain Md Shakhawat
 

What's hot (20)

PDF
Master theorem
fika sweety
 
PPTX
Radix and Merge Sort
Gelo Maribbay
 
PPTX
Rabin Carp String Matching algorithm
sabiya sabiya
 
PPTX
Divide and conquer - Quick sort
Madhu Bala
 
PDF
Minimum spanning tree
Amit Kumar Rathi
 
PPTX
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
PPT
Hash table
Rajendran
 
PPTX
Linked lists a
Khuram Shahzad
 
PPT
Breadth first search and depth first search
Hossain Md Shakhawat
 
PPT
Divide and Conquer
Dr Shashikant Athawale
 
PDF
Red black tree
Dr Sandeep Kumar Poonia
 
PPTX
Bruteforce algorithm
Rezwan Siam
 
PPTX
Merge Sort
Nikhil Sonkamble
 
PDF
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
PPT
Data Structure and Algorithms Hashing
ManishPrajapati78
 
PPT
Basic Garbage Collection Techniques
An Khuong
 
PPT
Dinive conquer algorithm
Mohd Arif
 
PPT
Prim's Algorithm on minimum spanning tree
oneous
 
PPT
Regular Grammar
Ruchika Sinha
 
PPTX
Quadratic probing
rajshreemuthiah
 
Master theorem
fika sweety
 
Radix and Merge Sort
Gelo Maribbay
 
Rabin Carp String Matching algorithm
sabiya sabiya
 
Divide and conquer - Quick sort
Madhu Bala
 
Minimum spanning tree
Amit Kumar Rathi
 
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Hash table
Rajendran
 
Linked lists a
Khuram Shahzad
 
Breadth first search and depth first search
Hossain Md Shakhawat
 
Divide and Conquer
Dr Shashikant Athawale
 
Red black tree
Dr Sandeep Kumar Poonia
 
Bruteforce algorithm
Rezwan Siam
 
Merge Sort
Nikhil Sonkamble
 
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Basic Garbage Collection Techniques
An Khuong
 
Dinive conquer algorithm
Mohd Arif
 
Prim's Algorithm on minimum spanning tree
oneous
 
Regular Grammar
Ruchika Sinha
 
Quadratic probing
rajshreemuthiah
 
Ad

Viewers also liked (20)

PDF
Algorithms, Union Find
Nikita Shpilevoy
 
PDF
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
PPT
Disjoint sets
Core Condor
 
PDF
Challenges of Agile Software Development
Wei (Terence) Li
 
PPTX
Set data structure 2
Tech_MX
 
PDF
Distributed Development Best Practices
Sunil Mundra
 
PDF
Agile Best Practices For Distributed Development
Sunil Mundra
 
PPTX
Ben Reich - Continuous Integration Best Practices in Agile Environments
AgileSparks
 
PPTX
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Andrea Angella
 
PDF
07. disjoint set
Onkar Nath Sharma
 
PPTX
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
PPTX
Algorithmic Puzzles
Amrinder Arora
 
PPT
Sets and disjoint sets union123
Ankita Goyal
 
PPTX
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
PPTX
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
PPTX
Dynamic Programming - Part II
Amrinder Arora
 
PPTX
NP completeness
Amrinder Arora
 
PPTX
Dynamic Programming - Part 1
Amrinder Arora
 
PPTX
Online algorithms in Machine Learning
Amrinder Arora
 
PPTX
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Algorithms, Union Find
Nikita Shpilevoy
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Disjoint sets
Core Condor
 
Challenges of Agile Software Development
Wei (Terence) Li
 
Set data structure 2
Tech_MX
 
Distributed Development Best Practices
Sunil Mundra
 
Agile Best Practices For Distributed Development
Sunil Mundra
 
Ben Reich - Continuous Integration Best Practices in Agile Environments
AgileSparks
 
Advanced Algorithms #1 - Union/Find on Disjoint-set Data Structures.
Andrea Angella
 
07. disjoint set
Onkar Nath Sharma
 
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
Algorithmic Puzzles
Amrinder Arora
 
Sets and disjoint sets union123
Ankita Goyal
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Dynamic Programming - Part II
Amrinder Arora
 
NP completeness
Amrinder Arora
 
Dynamic Programming - Part 1
Amrinder Arora
 
Online algorithms in Machine Learning
Amrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Ad

Similar to Time complexity of union find (20)

PPT
Review session2
NEEDY12345
 
PDF
03-data-structures.pdf
Nash229987
 
PDF
MLSD18. Unsupervised Learning
BigML, Inc
 
PPT
Algo-Exercises-2-hash-AVL-Tree.ppt
HebaSamy22
 
PDF
Skiena algorithm 2007 lecture09 linear sorting
zukun
 
PPTX
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
 
PPTX
Path compression
DEEPIKA T
 
PPT
Enhance The K Means Algorithm On Spatial Dataset
AlaaZ
 
PDF
Minimum Spanning Trees Artificial Intelligence
jiraf23341
 
PPTX
algorithm assignmenteeeeeee.pptx
kassahungebrie
 
PDF
Sienna6bst 120411102353-phpapp02
Getachew Ganfur
 
PPT
Unit-2-Sorting (Merge+Quick+Heap+Binary Searach).ppt
sajalsinghal1512
 
PPT
Fundamentals of data structures
Niraj Agarwal
 
PPT
Top school in noida
Edhole.com
 
PPTX
Dag representation of basic blocks
Jothi Lakshmi
 
PDF
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
PDF
Heap
Arun
 
PPTX
Scapegoat Tree
Sams Uddin Ahamed
 
PPT
Advanced Data Structures & Algorithm Analysi
Sreedhar Chowdam
 
PDF
module2_dIVIDEncONQUER_2022.pdf
Shiwani Gupta
 
Review session2
NEEDY12345
 
03-data-structures.pdf
Nash229987
 
MLSD18. Unsupervised Learning
BigML, Inc
 
Algo-Exercises-2-hash-AVL-Tree.ppt
HebaSamy22
 
Skiena algorithm 2007 lecture09 linear sorting
zukun
 
Linear Programming- Leacture-16-lp1.pptx
SarahKoech1
 
Path compression
DEEPIKA T
 
Enhance The K Means Algorithm On Spatial Dataset
AlaaZ
 
Minimum Spanning Trees Artificial Intelligence
jiraf23341
 
algorithm assignmenteeeeeee.pptx
kassahungebrie
 
Sienna6bst 120411102353-phpapp02
Getachew Ganfur
 
Unit-2-Sorting (Merge+Quick+Heap+Binary Searach).ppt
sajalsinghal1512
 
Fundamentals of data structures
Niraj Agarwal
 
Top school in noida
Edhole.com
 
Dag representation of basic blocks
Jothi Lakshmi
 
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
Heap
Arun
 
Scapegoat Tree
Sams Uddin Ahamed
 
Advanced Data Structures & Algorithm Analysi
Sreedhar Chowdam
 
module2_dIVIDEncONQUER_2022.pdf
Shiwani Gupta
 

Recently uploaded (20)

PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
Presentation about variables and constant.pptx
kr2589474
 
Presentation about variables and constant.pptx
safalsingh810
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 

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