Consider the following graph. If there is ever a decision between multiple neighbor nodes in the BFS or DFS algorithms, assume we always choose the letter closest to the beginning of the alphabet first.
In what order will the nodes be visited using Breadth First Search and Depth First Search?
(A) A, B, D, C, E, G, F, H and A, B, C, E, H, F, G, D respectively
(B) A, B, C, E, H, F, G, D and A, B, D, C, E, G, F, H respectively
(C) A, B, C, E, H, F, G, D and A, B, D, C, E, G, H, F respectively
(D) A, B, D, C, E, G, H, F and A, B, C, E, H, F, G, D respectively
Answer: (D)
Explanation: Order of nodes visiting in Breadth First Search is A, B, D, C, E, G, H, F and order of nodes visiting in Depth First Search is A, B, C, E, H, F, G, D.
Option (D) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...