Algorithms / 11 visualizations
Graph Algorithm Visualizers
BFS, DFS, shortest paths, union-find, topological order, spanning trees and grid flood fill.
Open the lab → Every one runs on your own input, step by step, with the code highlighted in Java, Python, C++, C or JavaScript. Free, no sign-up.
All graphs visualizations
- Breadth-First SearchO(V+E)
Visit the start, then all its neighbors, then their neighbors. A queue keeps nodes in the order they were found.
- Depth-First SearchO(V+E)
Go as deep as possible along one path, then back up and try the next branch. The call stack remembers where to return.
- Dijkstra's Shortest PathO((V+E) log V)
Always finalize the closest unfinished node next, then try to improve the distance to each of its neighbors.
- Bellman-Ford Shortest PathO(V·E)
Relax every edge, V − 1 times. After round i, every shortest path that uses at most i edges is correct. One more round that still improves something means a negative cycle.
- Floyd-Warshall All-Pairs Shortest PathsO(V³)
Allow one more node k as a stopover at a time. For every pair (i, j), going i → k → j might beat the best path found so far. After every k has been tried, all distances are final.
- Topological Sort (Kahn)O(V + E)
Count incoming edges (in-degree). Nodes with in-degree 0 can go first. Removing them frees up more nodes.
- Detect a Cycle in a Directed GraphO(V + E)
Colour nodes white (new), grey (on the current DFS path) and black (finished). Meeting a grey node again means you walked back into your own path: that edge closes a cycle. Meeting a black node is fine.
- Union-Find (Disjoint Sets)O(α(n))
Every set is a tree; its root names the set. find walks up to the root. union points one root at the other. If both ends of an edge already share a root, that edge closes a cycle.
- Kruskal's Minimum Spanning TreeO(E log E)
Sort edges by weight. Take each edge unless its two ends are already connected. Union-find answers "already connected?" almost instantly.
- Prim's Minimum Spanning TreeO(E log V)
Grow one tree from A. Always add the cheapest edge that reaches a node not yet in the tree.
- Number of Islands (Flood Fill)O(R·C)
Scan every cell. Each time you land on unvisited land, that is a new island: count it, then sink the whole island with DFS so it is never counted again.