Skip to content
GATEiit

GATE CSE 2017 Session 2 Q25: Possible BFS visiting order of a six-node graph

Syllabus topic: Graph traversals, minimum spanning trees and shortest paths

Question

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?

Undirected graph with six nodes: M, N, O in the top row and R, Q, P in the bottom row. Edges: M–N, N–O, M–R, M–Q, N–Q, O–Q, O–P and Q–P.
Tap the figure to enlarge

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: D (official GATE 2017 final answer key)

Concept used: In BFS every neighbour of the current node is enqueued before any node at a greater distance from the start is visited.

Concept notes

Loading notes…

First step: Take each option's first node as the source and check that nodes appear level by level in an order the queue allows.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Graph traversals, minimum spanning trees and shortest paths

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key