Skip to content

moonshineTP/kruskal-animation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kruskal's Algorithm Animator

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.

Features

  • 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.

Screenshots

Graph and DSU Visualization

Overview An overview of the graph alongside the DSU forest and array views.

Installation and Running

  1. Prerequisites: Python 3.8+, pygame and networkx.

    pip install pygame networkx
  2. Run the Application:

    python app.py
  3. Generate/Regenerate Graphs (Optional):

    python graph/generate.py

Project Structure

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.

Controls

  • 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.

License

This project is licensed under the MIT License.

About

Visualization of Kruskal's algorithm for MST. Support and compare various well-known strategies (small-to-large merging, path compression)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages