An interactive web-based visualization tool for Kruskal's Minimum Spanning Tree (MST) algorithm. This educational tool helps students and developers understand how Kruskal's algorithm works step-by-step, with support for both Disjoint Set Union (DSU) and DFS-based cycle detection approaches.
๐ Live Demo: https://kruskal-mst-visualizer.vercel.app/
- Kruskal + DSU (Union-Find): Visualizes the classic implementation using Disjoint Set Union with union by rank and optional path compression
- Kruskal + DFS: Demonstrates cycle detection using Depth-First Search on the current MST
- Graph Rendering: Dynamic graph visualization powered by Sigma.js and Graphology
- Step-by-Step Execution: Navigate through each step of the algorithm with Prev/Next buttons or use the slider
- Auto-Play Mode: Watch the algorithm run automatically with configurable speed
- Edge Tooltips: Hover over edges to see their details (endpoints and weight)
-
Edge States:
- ๐ก Yellow: Current edge being considered
- ๐ข Green: Edge chosen for MST
- โช Gray: Edge rejected (would create a cycle)
-
DSU Node States (when using DSU mode):
- ๐ข Cyan: Node calling
find(u)/ Root found - ๐ก Yellow: Node being traversed during find operation
- ๐ฃ Purple: Root node of the set
- ๐ข Cyan: Node calling
-
DFS Overlay (when using DFS mode):
- ๐ Orange: Candidate neighbors to explore
- ๐ข Cyan: Active DFS path
- โซ Gray: Dead branch (backtracked)
DSU Mode:
- Toggle Detailed DSU to see individual find/union operations
- Toggle Path Compression on/off to compare implementations
- Set Max Find Hops to limit step generation for deep trees
DFS Mode:
- Toggle Detailed DFS to see individual DFS traversal steps
- Set Max DFS Steps to limit step generation for complex searches
- Collapsible panels for mobile-friendly experience
- Adaptive layout for different screen sizes
- Touch-friendly controls
- Reorder panels by dragging the grip handle (โฎโฎ) on each panel header
- Desktop (>1024px): Drag panels within their column (left, middle, right)

- Mobile/Tablet (โค1024px): Freely drag any panel to any position in the single-column layout

- Customize your workspace to focus on what matters most to you
- Node.js (v18 or higher recommended)
- npm or yarn
# Clone the repository
git clone https://github.com/yourusername/kruskal-mst-visualizer.git
cd kruskal-mst-visualizer
# Install dependencies
npm install
# Start development server
npm run devThe app will be available at http://localhost:5173
npm run build
npm run previewEnter your graph in the input panel using the format:
N M
u1 v1 w1
u2 v2 w2
...
Where:
N= number of verticesM= number of edges- Each edge line contains:
u v w(start vertex, end vertex, weight)
Example:
5 8
1 2 1
1 3 4
1 5 1
2 4 2
2 5 1
3 4 3
3 5 3
4 5 2
Click "Tแบฃi ฤแป thแป" (Load Graph) to visualize your graph.
Select between:
- Kruskal + DSU: Uses Union-Find data structure
- Kruskal + DFS: Uses DFS for cycle detection
- Use Prev/Next buttons to step through manually
- Use the slider to jump to any step
- Click Play for automatic playback
- Watch the Code Panel to see which line is being executed
- Read the Explanation Panel for Vietnamese explanations of each step
- Check the DSU/DFS State Panel for internal data structure states
- Frontend Framework: React 19 with TypeScript
- Build Tool: Vite (using Rolldown)
- Graph Visualization: Sigma.js + Graphology
- Drag & Drop: @dnd-kit for panel reordering
- Code Highlighting: Prism React Renderer
- Deployment: Vercel
- Analytics: Vercel Speed Insights
kruskal-mst-visualizer/
โโโ src/
โ โโโ components/ # React components
โ โ โโโ CodeViewer.tsx # Python code display with highlighting
โ โ โโโ CollapsiblePanel.tsx # Collapsible wrapper for panels
โ โ โโโ ControlPanel.tsx # Playback controls
โ โ โโโ DFSPanel.tsx # DFS state visualization
โ โ โโโ DraggablePanel.tsx # Drag & drop wrapper for panels
โ โ โโโ DSUPanel.tsx # DSU state table
โ โ โโโ EdgeListPanel.tsx # Sorted edge list
โ โ โโโ ExplanationPanel.tsx # Step explanations
โ โ โโโ GraphInput.tsx # Graph input form
โ โ โโโ GraphRenderer.tsx # Sigma.js graph visualization
โ โ โโโ HelpModal.tsx # Color legend modal
โ โโโ engine/ # Algorithm implementations
โ โ โโโ kruskalDsu.ts # Kruskal + DSU step generator
โ โ โโโ kruskalDfs.ts # Kruskal + DFS step generator
โ โ โโโ parser.ts # Graph input parser
โ โ โโโ types.ts # TypeScript type definitions
โ โโโ App.tsx # Main application component
โ โโโ App.css # Application styles
โ โโโ main.tsx # Entry point
โโโ scripts/
โ โโโ test-all.ts # Automated testing script
โโโ test-cases/ # Test input/output files
โโโ package.json
Run the automated tests to verify algorithm correctness:
npx tsx scripts/test-all.tsThis will run the algorithm against all test cases in src/test-cases/ and compare outputs.
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
This project is open source and available under the MIT License.
This project was developed as part of Project I course at Hanoi University of Science and Technology. The full LaTeX report is available in kruskal_mst_visualizer_report_en.pdf.
- Inspired by the need for better algorithm visualization tools in computer science education
- Built with modern web technologies for accessibility and performance
- Ms. Nguyแป n Khรกnh Phฦฐฦกng โ the instructor who guided the Project I course at Hanoi University of Science and Technology, and whose guidance was instrumental throughout the development of this project.
Made with โค๏ธ for algorithm learners everywhere





