Graph Traversal Visualizer

Explore BFS and DFS algorithms with interactive graph visualization

Graph Setup

Traversal Controls

Graph Visualization

Nodes

0

Edges

0

Visited

0

Frontier

0

Traversal Order

Help

What are BFS and DFS?
  • Breadth-First Search (BFS): Explores level by level using a queue
  • BFS visits all neighbors at distance k before visiting nodes at distance k+1
  • Guarantees shortest path in unweighted graphs
  • Depth-First Search (DFS): Explores as deep as possible before backtracking
  • DFS uses a stack (or recursion) and explores one branch completely before trying others
  • Useful for cycle detection, topological sorting, and maze solving
How to Use
  • Add nodes by entering labels (A, B, C, etc.)
  • Connect nodes by selecting two nodes and clicking Add Edge
  • Choose directed or undirected graph type
  • Select a start node and traversal algorithm
  • Use Start to animate or Step to advance manually
  • Blue nodes are in the frontier, green nodes are visited, red is the current node
Key Differences
  • Data Structure: BFS uses queue (FIFO), DFS uses stack (LIFO)
  • Exploration: BFS goes wide, DFS goes deep
  • Optimality: BFS finds shortest path, DFS does not guarantee it
  • Memory: BFS uses more memory for wide graphs, DFS uses less
  • Use Cases: BFS for shortest path, web crawling; DFS for topological sort, cycle detection