Data Structures19 sections · 729 units
Open in Course

Connected Query

Same tree check

Check if u and v are in the same tree: ```pseudocode function connected(u, v): return findRoot(u) = findRoot(v)


This replaces Union-Find for connectivity but with added power:

- Supports edge deletion (cut)
- Supports path queries
- Supports rerooting

Union-Find is faster ($O(\alpha(n))$ vs $O(\log n)$) but limited to connectivity. Time: $O(\log n)$ amortized.