AiTechWorlds
AiTechWorlds
Animate Breadth-First Search exploring a graph level by level with a live queue, synced code, and draggable nodes.
from collections import deque
def bfs(adj, start):
vis = {start}
q = deque([start])
while q:
u = q.popleft()
for v in adj[u]:
if v not in vis:
vis.add(v); q.append(v)BFS explores a graph level by level using a queue, visiting all neighbors of a node before moving deeper. It finds the shortest path in unweighted graphs.
| Time | O(V + E) |
| Space | O(V) |
| Graph | Undirected, unweighted |
The BFS Visualizer animates how Breadth-First Search works: starting from a source node, it explores all neighbors at the current depth before moving deeper, using a FIFO queue. BFS runs in O(V + E) time, uses O(V) space, and finds the shortest path in unweighted graphs. Drag nodes to rearrange the graph and watch the queue update each step.
Generate a graph
Click New Graph or set the node-count slider to create a random graph.
Play the animation
Press Play to watch the queue drive the level-by-level traversal.
Step and scrub
Use Step Forward/Back or the timeline to inspect each enqueue and dequeue.
Read the synced code
The highlighted pseudocode line tracks the traversal; switch tabs for C++, Java, Python, or JavaScript.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.