The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is:

View worked solution
Answer: C
Based on the graph structure, the connections between the vertices are as follows:
- is connected to and .
- is connected to and .
- is connected to and .
- is connected to .
Let us trace the Breadth First Search (BFS) traversal starting from vertex using a FIFO queue:
- Start at : Visit . Queue = .
- Dequeue : Visit its neighbors and . Queue = .
- Dequeue : Visit its unvisited neighbors and . Queue = .
- Dequeue : Visit its unvisited neighbor . Queue = .
- Dequeue remaining: Dequeue and visit , then , and finally .
This sequence yields the traversal order .
Why Option D () is incorrect:
Because is dequeued before , the neighbor of (which is ) is enqueued before the neighbor of (which is ). Due to the FIFO property of the queue, must be dequeued and visited before . Therefore, is a valid BFS order, but is not.
Free practice · Your answers on this page are not saved.
