Skip to main content

Graph Vis

BFS • DFS • Shortest Path

Click "Generate" to run BFS and see steps.

1x
Ready
Algorithm Details

Click "Generate" to run BFS and see steps.

BFS Complexity

Time

O(V + E)

Space

O(V)

BFS
1def bfs(graph, start):
2 visited = set()
3 queue = deque([start])
4 while queue:
5 node = queue.popleft()
6 if node in visited: continue
7 visited.add(node)
8 for neighbor in graph[node]:
9 queue.append(neighbor)