This project implements Prim's algorithm for finding the Minimum Spanning Tree (MST) of a graph.
The implementation uses Prim's algorithm with a binary heap-based priority queue to efficiently find the MST of an undirected graph. The time complexity is O(E log V), where E is the number of edges and V is the number of vertices.
- Binary heap-based priority queue with Extract-Min, Decrease-Key, and Insert operations
- Efficient implementation of Prim's algorithm
- Support for reading graph input files and writing MST output files
- Comprehensive test suite with various graph examples
# Compile the program
make
# Run the program with input and output files
./mst input_mst.txt output_mst.txt
# Run the test suite
make test
# Clean up generated files
make cleanThe input files follow this format:
[num_vertices]<tab>[num_edges]<tab>[start vertex ID]
[vertex ID]<tab>[vertex ID]<tab>[weight]
[vertex ID]<tab>[vertex ID]<tab>[weight]
...
The output files follow this format:
[vertex ID]<tab>[predecessor]
[vertex ID]<tab>[predecessor]
...
Where NIL is used to indicate the root vertex (no predecessor).
The project includes several test cases:
- Standard example from the assignment specification
- Small graph with 4 vertices and 5 edges
- Medium graph with 7 vertices and 12 edges
- Medium-large graph with 10 vertices and 15 edges
- Large graph with 15 vertices and 21 edges
- GeeksForGeeks MST example
For more details on the test cases, see data/README.md.
The implementation includes:
- An adjacency list representation of the graph
- A binary min-heap for the priority queue
- Efficient heap operations (extract-min, decrease-key)
- Prim's algorithm for MST computation
This project implements Prim's algorithm using a binary heap-based priority queue to find the minimum spanning tree of an undirected graph. The implementation includes the following operations:
- Extract-Min
- Decrease-Key
- Min-Heapify
- Insertion
- C compiler with GCC
- Python 3 (for running tests)
To build the project, run:
makeThis will compile the source code and generate the executable mst.
To run the program with the default input and output files:
make runOr to run with custom input and output files:
./mst <input_file> <output_file>The project includes a comprehensive test suite to verify the correctness and performance of the implementation.
To run all tests:
make testTo run only performance tests:
make test-performanceSee the test directory README for more details on the test suite.
For more detailed information about the algorithm and implementation, see the specifications document.
To clean up the build artifacts:
make cleanThis will remove the executable and any object files.