Open
Description
Title: Union Find
Directory: Graph
Name: Daniel Yu-cua
Define You:
- Hacktoberfest2022 Participant
- Contributor
Problem
Write to program in Python to implement a Disjoint set also known as Union Find. A disjoint set is a data structure that stores a collection of "disjoint" (non-overlapping) sets. This data structure is useful to determine whether two vertices of a graph belong to the same component, or whether an edge between them would result in a cycle. It is a key component in implementing Kruskal's algorithm to find the minimum spanning tree.
Type of change
What sort of change have you made:
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Code style update (formatting, local variables)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
- This change requires a documentation update
Input:
UnionFind(5)
union(1,2)
union(4,5)
isConnected(1,2)
isConnected(3,4)
Output:
1 2 3 4 5
1-2 3 4 5
1-2 3 4-5
True
False
@prathimacode-hub Please assign me this issue, I'll be contributing as a Hacktoberfest 2022 participant.