0PricingLogin
Competitive Programming Academy · Lesson

DSU with Path Compression

Find and union in near-constant time.

What a DSU Tracks

A Disjoint Set Union keeps items grouped into non-overlapping sets, so you can ask if two things already belong together. 🤝

Sets as Trees

DSU stores each set as a tree. Every element points to a parent, and the topmost node, the root, is the unique name of the whole group.

All lessons in this course

  1. DSU with Path Compression
  2. Union by Rank and Components
  3. Kruskal's Minimum Spanning Tree
  4. Prim's MST with a Heap
← Back to Competitive Programming Academy