AlgoPrecision

Graph Visualizer

Graph Traversal

Trace BFS, DFS, and Dijkstra across a weighted directed graph with frontier, visited, settled, and distance state.

O(V + E)
4251731ABCDEF

Step Note

Start BFS with the chosen node in the queue.

Details
function bfs(graph: Graph, start: Node) {
  const queue = [start]
  while (queue.length > 0) {
    const node = queue.shift()
    visit(node)
    for (const neighbor of graph.neighbors(node)) {
      queue.push(neighbor)
    }
  }
}