Q. In which scenario would BFS be preferred over DFS?
A.
Finding the shortest path in an unweighted graph
B.
Finding a path in a maze
C.
Topological sorting
D.
Finding connected components
Solution
BFS is preferred for finding the shortest path in an unweighted graph because it explores all neighbors at the present depth prior to moving on to nodes at the next depth level.
Correct Answer:
A
— Finding the shortest path in an unweighted graph
Q. What is the main difference in traversal order between BFS and DFS?
A.
BFS uses a stack, DFS uses a queue
B.
BFS uses a queue, DFS uses a stack
C.
BFS is depth-first, DFS is breadth-first
D.
There is no difference
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:
B
— BFS uses a queue, DFS uses a stack
Q. Which traversal method is more memory efficient for sparse graphs?
A.
BFS
B.
DFS
C.
Both are equal
D.
Neither is efficient
Solution
DFS is generally more memory efficient for sparse graphs as it can use less space compared to BFS, which needs to store all nodes at the current level.