Skip to content

BFS vs DFS Traversal Animator

How to Use

  1. Click "Start" to begin both traversals simultaneously
  2. Click "Step" to advance both traversals one step at a time
  3. Watch the queue (BFS) and stack (DFS) update in real time
  4. Use the speed slider to control animation speed
  5. Click "Reset" to start over

About

BFS explores the graph level by level using a queue (FIFO), guaranteeing the shortest path in unweighted graphs. DFS explores deeply along each path using a stack (LIFO), useful for cycle detection and exhaustive path enumeration. Watch how the same graph produces different visit orders.