Graph Visualizer
Graph Traversal
Trace BFS, DFS, and Dijkstra across a weighted directed graph with frontier, visited, settled, and distance state.
O(V + E)
Step Note
Start DFS with the chosen node on the stack.
function dfs(graph: Graph, start: Node) {
const stack = [start]
while (stack.length > 0) {
const node = stack.pop()
visit(node)
for (const neighbor of graph.neighbors(node)) {
stack.push(neighbor)
}
}
}