Algorithms and Data Structures · Senior · Question 6 of 75

What makes union-find operations nearly O(1)?

Explanation

Path compression points nodes directly at the root during find; union by rank attaches the shorter tree under the taller. Together they give O(α(n)) amortized, where α (inverse Ackermann) is below 5 for any realistic n.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 6

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz