Skip to content

xsparsh1/DisjointSet-Union

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

DisjointSet-Union-CPP

This repository contains an implementation of the Disjoint Set Union (DSU) or Union-Find data structure in C++.

Features

  • Union by Size
  • Path Compression
  • Nearly constant time operations - O(4(α)) α - Aplha
  • Simple and clean OOP design

Concepts Covered

  • Graph components
  • Union-Find data structure
  • Optimized merging and parent tracking

Example Usage

DisjoinSet ds(7);
ds.unionBySize(0, 1);
ds.unionBySize(1, 3);
if (ds.ultimateParent(4) == ds.ultimateParent(3))
    cout << "Same Component";
else
    cout << "Different Components";

Compile & Run

  • g++ DisjointSet.cpp -o DisjointSet
  • ./DisjointSet

Author

About

Efficient C++ implementation of Disjoint Set Union (Union-Find) with Path Compression and Union by Size. Ideal for DSA practice and graph problems.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages