Solution
Breadth-First Search (BFS) explores a graph level by level, using a queue. It is well suited to finding the shortest path between two nodes (for example, the degree of separation in a social network) and is more suited for shallow graphs.
Depth-First Search (DFS) explores as far down a branch as possible before backtracking, using a stack. It is useful for puzzles such as mazes and is more memory-efficient for deep graphs.
Both have time complexity . BFS is preferable when the shortest path or a level-order view is needed; DFS is preferable when memory is limited on deep graphs or when one path should be explored fully before others.