C-Plus-Plus
C-Plus-Plus copied to clipboard
Implement Kruskal’s MST Algorithm with Flexible Input Options
Implemented Kruskal’s Minimum Spanning Tree (MST) algorithm in C++. This update introduces a new implementation that includes:
- Edge Struct: Represents an edge in the graph with source, destination, and weight.
- DisjointSet Class: Manages union-find operations to detect cycles and union sets efficiently.
- kruskalMST Function: Computes the MST using Kruskal's algorithm and prints the edges included in the MST.
-
Flexible Input Options:
- Static Input: A predefined adjacency matrix for ease of testing.
- Dynamic Input: Allows users to input their own adjacency matrix and number of vertices.
The code now supports user interaction for dynamic input, provides clear error handling for invalid choices, and includes thorough documentation and comments for clarity.
Checklist
- [x] Added description of change
- [x] Added file name matches File name guidelines
- [x] Added tests and example, test must pass
- [x] Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
- [x] Relevant documentation/comments is changed or added
- [x] PR title follows semantic commit guidelines
- [x] Search previous suggestions before making a new one, as yours may be a duplicate.
- [x] I acknowledge that all my contributions will be made under the project's license.
Notes: This update provides a complete implementation of Kruskal’s algorithm with options for both static and dynamic input, improving usability and flexibility for testing.