UTSAVS26 / PySnippets

Collection of reusable Python code snippets for all.
https://sites.google.com/view/pysnippets/
MIT License
18 stars 50 forks source link

[Feature Request]: Addition of disjoint set algorithms #178

Open PavanTeja2005 opened 1 day ago

PavanTeja2005 commented 1 day ago

Is there an existing issue for this?

Feature Description

I propose the addition of the Disjoint Set (Union-Find) algorithm implementation to enhance the project's algorithmic capabilities, especially for use cases involving dynamic connectivity, Kruskal’s algorithm, or similar applications. Key Features of the Disjoint Set Algorithm:

Union by Rank/Size - Optimizes merging of sets based on size or rank.
Path Compression - Ensures faster lookups by flattening the structure of the tree during the find operation.
Operations - Efficient find and union functions, both of which run in nearly constant time (amortized inverse Ackermann time).

Suggested Changes:

Create a new file or folder named disjoint_set.py or union_find.py.
Implement the Disjoint Set class with:
    find(x) function with path compression.
    union(x, y) function with union by rank/size.
Add unit tests to verify correctness of the algorithm for various scenarios (e.g., handling isolated nodes, union of disjoint sets, etc.).

Potential Use Cases:

Graph algorithms (Kruskal's Minimum Spanning Tree).
Network connectivity problems.
Image segmentation algorithms.

Record

Full Name

Venkata Pavan Teja Bathula

Participant Role

GSSOC

github-actions[bot] commented 1 day ago

🙌 Thank you for bringing this issue to our attention! We appreciate your input and will investigate it as soon as possible.

Feel free to join our community on Discord to discuss more!