Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the complexity of path compression technique for disjoint set algorithm?

I was studying the disjoint algorithm with the union by rank and path compression.

It is clear to me if Union by rank is used then the find() operation complexity is O(log(n)).

But I wonder what is the complexity of the path compression technique for disjoint set algorithm if I use union by rank or not use union by rank?

like image 836
Muidul Alam 2hin Avatar asked Oct 21 '25 15:10

Muidul Alam 2hin


1 Answers

If you link the sets together arbitrarily instead of using union-by-rank or union-by-size, then path compression alone will achieve O(m log n) time for any sequence of n unions and m finds (with m > n). That makes the amortized cost of a find operation O(log n)

The proof is difficult, so here's an excellent confirmatory reference: https://www.cs.princeton.edu/courses/archive/spring13/cos423/lectures/UnionFind.pdf

like image 135
Matt Timmermans Avatar answered Oct 23 '25 06:10

Matt Timmermans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!