Traversal Algorithms
BFS: Explores level-by-level, using a queue. Good for shortest paths.
DFS: Goes deep into each branch, using a stack. Good for cycle detection.
Time Complexity = O(V + E), Space Complexity = O(V)
BFS explores nodes in layers, always processing the closest unvisited nodes first.
BFS is used in shortest path finding, level-order tree traversal, and finding connected components.
How would you find the shortest path from your home to a friend's house using BFS?
Time Complexity = O(V + E), Space Complexity = O(V)
Use this formula to calculate the relationship between different variables in this concept.
Finding the shortest path in a maze by exploring all adjacent cells before going further.