Skip to main content

๐ŸŽฎ BFS / DFS (Practice)

Companion to the BFS & DFS guide. Watch BFS explore a graph level by level, then implement it with a queue.

๐ŸŽฌ Watch it workโ€‹

BFS โ€” level-by-level explorationStep 1 / 13
1
2
3
4
5
6
Start BFS at node 1; enqueue it.

๐Ÿ Your turnโ€‹

Loading editorโ€ฆ

๐Ÿง  Challenge yourselfโ€‹

  1. Rewrite it as DFS using a stack (or recursion).
  2. Modify BFS to return the shortest-path distance from start to every node.
  3. How would you detect a cycle during traversal?

Continue the path โ†’ Hashing Patterns