BFS (Breadth First Search) Simulator
Build interactive graphs and watch BFS explore networks level-by-level using a visual queue.
About This Simulation
This BFS simulator lets you draw your own graph, pick a start node and watch Breadth First Search visit it level by level. The queue is shown on screen, so you can see exactly which node is added and removed at every step.
Features
- Add nodes and edges on an interactive canvas
- Choose the start node and load ready-made example graphs
- Live BFS queue with enqueue and dequeue highlighted
- Step forward, step back, play and pause with adjustable speed
- Visited, in-queue and finished nodes shown in different colours
Explanation
Breadth First Search (BFS) is a graph traversal algorithm that explores all neighbours of a node before moving one level deeper. It uses a queue (first in, first out), so nodes are visited in order of their distance, in edges, from the start node.
How it works
- Mark the start node as visited and put it in the queue.
- Remove the node at the front of the queue and process it.
- For each neighbour of that node that has not been visited, mark it visited, record its parent and add it to the back of the queue.
- Repeat until the queue is empty. Every reachable node is visited exactly once.
- Following the parent links back from any node gives a shortest path (fewest edges) from the start node.
Why it matters
BFS finds shortest paths in unweighted graphs and is the basis of level-order tree traversal, connected-component counting, bipartite checking, web crawlers and social-network 'degrees of separation'. It is a core topic in data structures and algorithms courses such as CSE220 and CSE221.
Frequently Asked Questions
What data structure does BFS use?
BFS uses a queue. The node that was discovered first is processed first, which is what makes the search expand level by level.
What is the time complexity of BFS?
O(V + E) with an adjacency list, where V is the number of vertices and E the number of edges, because every vertex is enqueued once and every edge is checked once (twice in an undirected graph). With an adjacency matrix it is O(V²).
Does BFS find the shortest path?
Yes, but only in unweighted graphs (or graphs where every edge has the same weight). For weighted graphs use Dijkstra's algorithm or Bellman-Ford.
What is the difference between BFS and DFS?
BFS uses a queue and explores level by level, so it finds the shortest path in edges. DFS uses a stack (or recursion) and goes as deep as possible before backtracking. Both run in O(V + E).
Topics covered
- Breadth First Search
- Graph Traversal
- Queue (FIFO)
- Shortest Path in Unweighted Graphs
- BFS Tree
- Time Complexity O(V + E)
Tags
- bfs
- queue
- shortest path unweighted
Related Simulations
Algorithms
Searching Algorithms
Run linear, binary, ternary and quaternary search on your own array and step through the code one line at a time.
Algorithms
Sorting Algorithm Visualiser
Visualise sorting algorithms
Algorithms
A* Algorithm
Show pathfinding using cost, heuristic, and total estimated distance.
Algorithms
DFS (Depth First Search) Simulator
Build interactive graphs and watch DFS plunge down deep paths and backtrack using a visual stack.

