Interactive pathfinding and sorting visualizer
Visited Nodes 0
Shortest Path Steps 0
Status Ready
Comparisons 0
Swaps / Writes 0
Array Size 48
Status Ready
Time and space
AlgoVis runs nine textbook algorithms on one dark canvas. Pathfinding expands a grid cell by cell. Sorting redraws a bar chart comparison by comparison. Nothing is uploaded. The notes under the fold are ordinary HTML and stay readable with scripts off.
How to use it
- Drag to draw or erase walls, or drag the start and the goal. Generate Maze builds a connected maze.
- Press Play to watch the trace, Step to advance one frame, and Speed to change the pace.
- Switch to Sorting, choose an algorithm, then shuffle the array, reverse it, or make it nearly sorted.
Pathfinding
Moves are four-directional, and every step costs 1. A* orders the frontier by distance traveled plus the Manhattan distance to the goal. That heuristic is consistent, so the first time the goal is expanded the route is shortest. Dijkstra orders the frontier by distance traveled alone and is optimal on these unit weights. BFS expands in rings and is optimal on an unweighted grid. DFS follows one branch first and returns a valid route that can be longer than the shortest path. The time bounds below assume a binary heap for A* and Dijkstra.
| Algorithm | Time | Space | Result |
|---|---|---|---|
| A* | O((V+E) log V) | O(V) | Shortest path |
| Dijkstra | O((V+E) log V) | O(V) | Shortest path |
| BFS | O(V+E) | O(V) | Shortest path |
| DFS | O(V+E) | O(V) | Valid path |
Sorting
QuickSort partitions around the last value in the range. Its average time is O(n log n) and a sorted input can fall to O(n²); the extra memory is the recursion stack, O(log n) on average and O(n) at worst. MergeSort merges sorted halves and counts every write; it is stable and always O(n log n), with O(n) extra memory. HeapSort builds a max-heap and extracts the largest remaining value into a sorted suffix; it is O(n log n) with O(1) extra memory and is not stable. InsertionSort slides each new value back through a sorted prefix. BubbleSort swaps adjacent inversions and grows a sorted suffix from the right. Both are O(n²) in the worst case, and both finish a sorted array in one pass. The counters are the real comparison, swap, and write events from that trace.
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| QuickSort | O(n log n) | O(n log n) | O(n²) | O(log n) | No |
| MergeSort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes |
| HeapSort | O(n log n) | O(n log n) | O(n log n) | O(1) | No |
| InsertionSort | O(n) | O(n²) | O(n²) | O(1) | Yes |
| BubbleSort | O(n) | O(n²) | O(n²) | O(1) | Yes |
Questions
Does A* with Manhattan distance find the shortest path?
Yes. On a four-direction grid every move costs 1, and Manhattan distance never overestimates the remaining moves. The heuristic is consistent, so the first time A* expands the goal the path is optimal. Dijkstra and BFS also return a shortest path on this grid. DFS returns a valid route that can be longer.
What do the counters measure?
Visited nodes count cells taken off the frontier and expanded. Shortest path steps count the moves from the start cell to the goal, not the start cell itself. Sorting comparisons count element order tests. Swaps count exchanges. MergeSort counts writes into the array instead of swaps.
Is a generated maze always solvable?
Yes. Generation is a recursive backtracker over the odd cells, so every open passage is connected. You can still draw walls that close the route. If no route remains, the status becomes No Path and the path length stays at zero.
Which sorts are stable, and what do they cost?
MergeSort is stable, uses extra memory linear in the array, and is O(n log n) in every case. QuickSort averages O(n log n) and can fall to O(n²). HeapSort is O(n log n) with O(1) extra memory and is not stable. InsertionSort and BubbleSort are O(n²), and InsertionSort is fast on nearly sorted data.
Does the visualizer send the grid anywhere?
No. Search and sorting run in this page. The article under the canvas is plain HTML and stays readable with scripts disabled. The canvas needs JavaScript.
Sponsored links
- Surfshark — VPN service. The link opens the current plan page.
- Corel — Creative software. The link opens the current offers page.
Advertising disclosure: if you buy through these links, we may earn a commission at no extra cost to you.
AlgoVis · pathfinding and sorting in the browser