A comprehensive, production-ready web application for visualizing graph traversal and pathfinding algorithms with real-time interactive controls, dark mode, PWA support, and advanced features.
π Live Demo | π Documentation | π Report Bug
- Breadth-First Search (BFS) - Level-by-level exploration, guarantees shortest path in unweighted graphs
- Depth-First Search (DFS) - Deep branch exploration with backtracking
- Dijkstra's Algorithm - Optimal shortest path in weighted graphs
- A Algorithm* - Heuristic-guided optimal pathfinding
- Bidirectional BFS - Searches from both start and end simultaneously (faster)
- Bellman-Ford Algorithm - Handles negative weights, detects negative cycles
- Greedy Best-First Search - Heuristic-only search (fast but not always optimal)
- β Real-time step-by-step animation with adjustable speed (1-100)
- β Multiple visualization modes: continuous, step-by-step, or pause/resume
- β Path highlighting with animated transitions
- β Color-coded node states: visiting, visited, path, walls, start, end
- β Edge weight visualization for weighted graphs
- β Performance statistics: nodes visited, path length, total distance, complexity
- Zoom & Pan: Mouse wheel zoom, pinch-to-zoom, pan with Alt+Drag
- Node Manipulation:
- Right-click β Set start node
- Shift + Right-click β Set end node
- Ctrl/Cmd + Click β Toggle walls/obstacles
- Click (custom mode) β Create nodes
- Undo/Redo: Full state management with Ctrl+Z/Ctrl+Y
- Import/Export: Save and load graphs as JSON or CSV
- Share: Generate shareable URLs with compressed graph data
- Download: Export visualization as PNG image
- Grid (10x10) - Regular grid for maze-solving
- Random Graph - Random nodes with probabilistic connections
- Weighted Graph - Pre-built weighted example
- Maze - Grid with random obstacles
- Simple Path - Linear path for testing
- Binary Tree - Balanced tree structure
- Diamond Pattern - Multiple paths with different costs
- Star Pattern - Radial hub-and-spoke layout
- Custom - Build your own graph from scratch
- 3 Built-in Themes:
- Light (default)
- Dark (OLED-friendly)
- Ocean (blue tones)
- Theme persistence via localStorage
- Smooth transitions between themes
- System preference detection (prefers-color-scheme)
- β Installable on mobile and desktop
- β Offline support via Service Worker
- β Fast loading with caching
- β App-like experience with fullscreen mode
- β Manifest with icons and shortcuts
- ARIA labels on all interactive elements
- Keyboard navigation with comprehensive shortcuts
- Focus indicators for keyboard users
- Screen reader support
- Reduced motion support for accessibility preferences
- High contrast themes available
| Shortcut | Action |
|---|---|
Space |
Start/Pause visualization |
R |
Reset current visualization |
S |
Step through algorithm (when paused) |
Ctrl/Cmd + Z |
Undo |
Ctrl/Cmd + Y |
Redo |
Ctrl/Cmd + S |
Export graph |
F |
Toggle fullscreen |
T |
Toggle theme |
- Pinch - Zoom in/out
- Two-finger drag - Pan canvas
- Tap - Select/create nodes
- Long press - Set start/end nodes
- A modern web browser (Chrome 90+, Firefox 88+, Safari 14+, Edge 90+)
- No build tools or dependencies required!
-
Clone the repository:
git clone https://github.com/UNC-GDSC/Graph-Algorithms-Visualizer.git cd Graph-Algorithms-Visualizer -
Serve the files (choose one):
# Using Python python -m http.server 8000 # Using Node.js npx http-server # Using PHP php -S localhost:8000 # Or simply open index.html in your browser open index.html # macOS start index.html # Windows xdg-open index.html # Linux
-
Navigate to
http://localhost:8000
- Select an algorithm from the dropdown (try A* to start)
- Choose a graph preset or create your own
- Adjust the speed slider to your preference
- Click Start or press
Spaceto begin visualization - Watch the algorithm explore and find the shortest path!
- Select "Custom" from the preset dropdown
- Click anywhere on the canvas to create nodes
- Right-click a node to set it as the start node (green)
- Shift + Right-click a node to set it as the end node (red)
- Ctrl/Cmd + Click nodes to toggle walls (black)
- Start the visualization to see your algorithm in action
- Run an algorithm on a graph preset
- Note the nodes visited and path length
- Reset and try a different algorithm
- Compare performance metrics!
- Create an interesting graph
- Click the Share button (π)
- The URL is automatically copied to your clipboard
- Share with friends or save for later!
- JSON format: Full graph structure with all metadata
- CSV format: Nodes and edges in spreadsheet-compatible format
- PNG image: Visual snapshot of the current state
Graph-Algorithms-Visualizer/
βββ index.html # Main HTML structure with semantic markup
βββ styles.css # Responsive CSS with theme support
βββ graph.js # Graph data structure & generators
βββ algorithms.js # 7 algorithm implementations
βββ visualizer.js # Canvas rendering engine
βββ main.js # Application controller
βββ utils.js # Utility functions & state management
βββ import-export.js # Graph I/O operations
βββ controls.js # Zoom, pan, touch & tutorial
βββ manifest.json # PWA manifest
βββ sw.js # Service Worker for offline support
βββ README.md # This file
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # MIT License
βββ package.json # npm metadata
- Pure Vanilla JavaScript (ES6+) - No frameworks, maximum performance
- HTML5 Canvas - Hardware-accelerated rendering
- CSS3 Variables - Dynamic theming support
- Service Workers - Offline-first PWA
- LocalStorage - State persistence
- URL Compression - Shareable graph links
Nodeclass: Individual graph nodes with propertiesGraphclass: Adjacency list representationGraphGeneratorclass: 9 preset generators
PriorityQueueclass: Min-heap for Dijkstra/A*Algorithmsclass: 7 static algorithm methods- Generator-based for step-by-step visualization
Utilsclass: Helper functions (debounce, storage, toast, etc.)StateManagerclass: Undo/redo with 50-state historyThemeManagerclass: Multi-theme support
GraphIOclass: JSON/CSV import/exportLZStringclass: URL compressionGraphTemplatesclass: Preset library
ZoomPanControllerclass: Zoom/pan with touch supportTutorialManagerclass: Interactive onboarding
Complexity: Time O(V + E), Space O(V)
Explores nodes level-by-level using a queue. Guarantees the shortest path in unweighted graphs.
Best for: Shortest path in unweighted graphs, level-order traversal
Complexity: Time O(V + E), Space O(V)
Explores as far as possible along each branch using a stack (or recursion).
Best for: Detecting cycles, topological sorting, maze solving
Complexity: Time O((V + E) log V), Space O(V)
Finds shortest path in weighted graphs with non-negative edge weights using a priority queue.
Best for: GPS navigation, network routing, shortest paths with costs
Complexity: Time O((V + E) log V), Space O(V)
Combines Dijkstra with heuristic (Euclidean distance) for goal-directed search.
Best for: Video game pathfinding, robotics, optimal routing
Complexity: Time O(V + E), Space O(V)
Searches from both start and end simultaneously, often finding paths faster.
Best for: Large graphs where start and end are known
Complexity: Time O(V Γ E), Space O(V)
Handles negative edge weights and detects negative cycles.
Best for: Currency arbitrage, network routing with costs
Complexity: Time O((V + E) log V), Space O(V)
Uses only heuristic for speed, but doesn't guarantee optimal path.
Best for: Quick approximate solutions, real-time scenarios
Edit utils.js:
this.themes = {
// ... existing themes
mytheme: {
name: 'My Theme',
colors: {
background: '#...',
surface: '#...',
// ... other colors
}
}
}- Add algorithm to
algorithms.js:
static* myAlgorithm(graph) {
// Implementation using yield for visualization
yield { type: 'visiting', node: current, ... };
yield { type: 'found', path: [...], ... };
}- Register in
getAlgorithm():
'my-algo': Algorithms.myAlgorithm- Add to HTML dropdown in
index.html
See CONTRIBUTING.md for detailed guidelines.
# Start local server
npm run start # or npm run serve
# Open browser to
http://localhost:8000- Linting: All JavaScript is syntax-validated
- No dependencies: Pure vanilla JS
- Browser compatibility: Tested on major browsers
- Performance: Optimized Canvas rendering
- Graph Size: Optimized for up to 1000 nodes
- Rendering: 60 FPS canvas updates
- Memory: Efficient adjacency list
- Caching: Service Worker caching for instant loads
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make changes and test thoroughly
- Commit:
git commit -am 'Add feature' - Push:
git push origin feature-name - Create a Pull Request
| Browser | Version | Support |
|---|---|---|
| Chrome | 90+ | β Full |
| Firefox | 88+ | β Full |
| Safari | 14+ | β Full |
| Edge | 90+ | β Full |
| Mobile Safari | 14+ | β Full |
| Chrome Android | 90+ | β Full |
- Algorithm comparison mode (coming soon)
- Negative edge weights only work with Bellman-Ford
- Some PWA features require HTTPS in production
- Algorithm comparison mode (side-by-side)
- Floyd-Warshall (all-pairs shortest path)
- Minimum spanning tree (Prim's, Kruskal's)
- Animation recording/export
- More graph layouts (force-directed, circular)
- Graph analytics (centrality, clustering)
- Collaborative editing
- Custom heuristics for A*
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 UNC-GDSC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
- Inspired by classic algorithm visualizers
- Built with β€οΈ using vanilla JavaScript
- Thanks to the open-source community
- Special thanks to UNC-GDSC members and contributors
- GitHub Issues: Create an issue
- GitHub Discussions: Join the conversation
- Repository: View on GitHub
If you find this project useful, please consider giving it a β on GitHub!
Built with β€οΈ by UNC-GDSC
Version: 2.0.0 (Production Ready) Last Updated: November 2024