███╗ ███╗███████╗████████╗ ████╗ ████║██╔════╝╚══██╔══╝ ██╔████╔██║███████╗ ██║ ██║╚██╔╝██║╚════██║ ██║ ██║ ╚═╝ ██║███████║ ██║ ╚═╝ ╚═╝╚══════╝ ╚═╝ALGORITHMS EXPERIMENTAL ANALYSIS
Comparing Kruskal's and Prim's algorithms through experimental analysis
https://github.com/msadeqsirjani/MSTree-Bench
A benchmarking toolkit for comparing Kruskal's and Prim's minimum spanning tree algorithms across various graph configurations, with visualization tools and performance analysis reports.
.
├── docs/ # Documentation
│ └── HW 4 - Experiments with MST Algorithms-1.pdf # Assignment specs
│
├── logs/ # Log files (created when running)
│
├── reports/ # Generated reports and visualizations
│ ├── mst_analysis_report.html # HTML report with analysis
│ ├── mst_analysis_report.md # Markdown version of the report
│ ├── comparison_plot.png # Performance comparison chart
│ ├── size_comparison.png # Graph size impact visualization
│ ├── density_comparison.png # Density impact visualization
│ └── ... # Other generated files
│
├── src/ # Source code
│ ├── main.py # Main entry point
│ ├── mst.py # MST algorithm implementations
│ ├── experiment.py # Experimental procedures
│ ├── report_generator.py # Report generation logic
│ └── logger.py # Logging utilities
│
├── venv/ # Virtual environment (created when running)
│
├── README.md # Project documentation
├── requirements.txt # Project dependencies
└── run.sh # Execution script
This project requires Python 3.6+ with the following packages:
- matplotlib
- numpy
The easiest way to run the project is by using the included run script:
./run.sh
This script will:
- Create a virtual environment if it doesn't exist
- Install required dependencies
- Create necessary directories
- Run the main program
- Deactivate the virtual environment when finished
Alternatively, you can run the project manually:
- Create and activate a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install the required packages:
pip install matplotlib numpy
- Run the main script:
python src/main.py
The project runs several experiments:
- Effect of Graph Size: Comparing algorithm performance as the number of vertices increases from 10 to 1000
- Effect of Graph Density: Comparing algorithm performance as the graph density changes from very sparse (0.01) to dense (0.9)
- Edge Count Comparison: Performance across different edge-to-vertex ratios for various graph sizes
- Crossover Point Analysis: Finding where Prim's algorithm becomes more efficient than Kruskal's
- Theoretical Analysis: Comparing experimental results with theoretical time complexities
After running the program, you can view the results in two formats:
A comprehensive HTML report is generated at:
reports/mst_analysis_report.html
A markdown version of the report is available at:
reports/mst_analysis_report.md
The reports include:
- Detailed descriptions of the algorithms
- Performance data tables
- Visualizations of the results
- Analysis of the findings
- MinHeap: Custom implementation for priority queue operations needed by Prim's algorithm
- DisjointSet: Implementation with path compression and union by rank for Kruskal's algorithm
Kruskal's algorithm uses a disjoint-set data structure with path compression and union by rank for efficiency. The implementation sorts all edges and adds them to the MST in order of increasing weight if they don't create a cycle.
Time complexity: O(E log E), where E is the number of edges.
Prim's algorithm uses a binary heap (priority queue) to efficiently select the next minimum-weight edge to add to the MST. It starts from a single vertex and grows the MST by adding one vertex at a time.
Time complexity: O(E log V), where V is the number of vertices.
The graph generation function creates random connected graphs with:
- Specified number of vertices (n)
- Specified number of edges (m)
- Random edge weights
- Guaranteed connectivity
Special handling is implemented for:
- Complete graphs
- Dense graphs (using deletion approach)
- Sparse graphs (using addition approach)
Detailed logging is implemented throughout the project, capturing:
- Experiment progress
- Graph generation details
- Algorithm execution
- Performance measurements
Logs are stored in the logs/
directory for debugging and analysis.