An interactive educational tool for visualizing Kruskal's Minimum Spanning Tree (MST) algorithm. This application allows users to explore how the algorithm works step-by-step, visualizing both the graph operations and the internal state of the Disjoint Set Union (DSU) data structure.
- Interactive Visualization: Watch the algorithm process edges one by one.
- Graph View: Visualizes vertices, edges, and their states (Considered, Accepted, Rejected).
- DSU Visualization:
- Forest View: Shows the disjoint sets as trees, dynamically updating as unions occur.
- Array View: Displays the underlying parent array state.
- Strategy Selection:
- Find Strategies: Path Compression vs. Simple Traversal.
- Union Strategies: Union by Rank/Size vs. Union by Index.
- Playback Controls: Play, Pause, Step Forward, Step Backward, and Speed control.
- Custom Graphs: Load various graph instances from the
graph/directory.
An overview of the graph alongside the DSU forest and array views.
-
Prerequisites: Python 3.8+,
pygameandnetworkx.pip install pygame networkx
-
Run the Application:
python app.py
-
Generate/Regenerate Graphs (Optional):
python graph/generate.py
The project is organized into modular components:
kruskal-animator/
├── app.py # Main entry point. Initializes the window and main loop.
├── component/ # Core application components.
│ ├── algo.py # Kruskal's algorithm and DSU strategy implementations.
│ ├── board.py # Visualization logic (Graph, DSU Forest, DSU Array).
│ ├── classes.py # Data structures (Graph, Vertex, Edge, DSU).
│ ├── panel.py # UI controls (Buttons, Dropdowns, Sliders).
│ └── session.py # Manages algorithm state, history, and timing.
├── graph/ # Graph instance files (.inp) and reference outputs (.out).
│ └── generate.py # Generate/regenerate graph instances.
├── images/ # Screenshots and assets.
└── test/ # Unit tests for planarity and MST correctness.
- Graph Dropdown: Select a different graph instance.
- Find/Union Strategy: Change the DSU heuristics on the fly.
- New/Reset: Start a fresh session.
- < / >: Step backward or forward manually.
- Play/Pause: Toggle automatic execution.
- Speed Slider: Adjust the animation speed.
This project is licensed under the MIT License.