The Breadth First Search (BFS) algorithm has been implemented using the queue data structure. Which one of the following is a possible order of visiting the nodes in the graph below?

View worked solution
Answer: D
In a Breadth-First Search (BFS) traversal, vertices must be visited level-by-level in increasing order of their shortest path distance from the starting vertex. That is, all vertices at distance from the start vertex must be visited before any vertex at distance is visited.
Let us analyze the graph's structure and the options:
- Option D (): If we start the BFS at vertex :
- Level 0 (distance 0):
- Level 1 (distance 1):
- Level 2 (distance 2):
- Level 3 (distance 3):
- Other Options: In options A, B, and C, a vertex at a greater distance is visited before all vertices at a closer distance are exhausted, which violates the BFS property. For example, in Option A (), starting at , the vertex (at distance 2) is visited before and (at distance 1).
Free practice · Your answers on this page are not saved.
