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(h)
DFS explores as far as possible along each branch before backtracking.
DFS is used for cycle detection, topological sorting, and finding strongly connected components.
How would you explore all rooms in a building by following each hallway as far as possible?
Time Complexity = O(V + E), Space Complexity = O(h)
Use this formula to calculate the relationship between different variables in this concept.
Detecting cycles in a graph by using DFS to find back edges.