Q. In which scenario is Breadth-First Search (BFS) preferred over Depth-First Search (DFS)?
A.
When memory is limited
B.
When the shortest path is required
C.
When the graph is very deep
D.
When cycles are present
Solution
BFS is preferred when the shortest path is required because it explores all neighbors at the present depth prior to moving on to nodes at the next depth level.
Correct Answer:
B
— When the shortest path is required
Q. What is the primary difference between BFS and DFS in terms of traversal strategy?
A.
BFS uses a queue, DFS uses a stack
B.
BFS uses a stack, DFS uses a queue
C.
BFS is faster than DFS
D.
DFS is always more memory efficient
Solution
BFS uses a queue to explore nodes level by level, while DFS uses a stack (or recursion) to explore as far as possible along each branch before backtracking.
Correct Answer:
A
— BFS uses a queue, DFS uses a stack