← Back to Index

BFS vs DFS

Interactive Graph Traversal
BFS
Mode
A
Start Node
0
Visited
0
Queue / Stack
Ready
Status
BFS visited / Queue
DFS visited / Stack
Current node / edge scan
Start node

Graph Canvas

Click empty space to add a node. Drag from one node to another to connect them. Double-click a node to set the start.

Queue

Traversal Order

Message

BFS visits level by level. DFS dives deep before backtracking.

How It Works

BFS and DFS use the same graph but different frontier rules. BFS removes from the front of a queue, so it explores in layers. DFS removes from the top of a stack, so it follows one branch as far as possible before returning.