Abstract


Use Cases

  • When you want to find the shortest path (in an unweighted graph)
  • When you prefer level-by-level expansion
  • When you want to avoid deep recursion

Complexity Analysis

  • Time Complexity:
  • Space Complexity: for the queue and visited

Pros

  • Guaranteed to find the shortest path
  • Handles cycles easily with visited
  • Safer for large/deep graphs (no stack overflow)

Cons

  • Slightly more verbose (requires queue)
  • Can use more memory than DFS

Code Example