How it works
Core operations
Find returns the root of an element, and union merges two trees under a single root.
Optimizations
Path compression flattens trees and union by rank keeps them shallow, giving near-constant amortized time.
When to use it
Use it for connectivity, cycle detection in undirected graphs, and Kruskal minimum spanning trees.