GateAI
Graph Traversals

GATE CSE 2017 Set 2 · Q15

MCQ1 markMedium

Time

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?

GATE CSE 2017 Set 2 Q15 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) POQNMR

Graph Traversals

Breadth First Search (BFS) visits all vertices at distance kk before visiting any vertex at distance k+1k+1 from the source vertex.

Let us evaluate the options:

  • (A) MNOPQR: Starts at MM. Distance-1 neighbors of MM are {N,R,Q}\{N, R, Q\}. However, OO (which is at distance 22) is visited before RR and QQ. Hence, invalid.

  • (B) NQMPOR: Starts at NN. Distance-1 neighbors of NN are {M,O,Q}\{M, O, Q\}. Here, PP (at distance 22) is visited before OO (at distance 11). Hence, invalid.

  • (C) QMNROP: Starts at QQ. Distance-1 neighbors of QQ are {M,N,O,P}\{M, N, O, P\}. Here, RR (at distance 22) is visited before OO and PP (at distance 11). Hence, invalid.

  • (D) POQNMR: Starts at PP.

    1. Enqueue PP. Level 00: PP.

    2. Dequeue PP, enqueue unvisited neighbors: O,QO, Q. Queue: [O,Q][O, Q]. Level 11: {O,Q}\{O, Q\}.

    3. Dequeue OO, enqueue unvisited neighbor: NN. Queue: [Q,N][Q, N].

    4. Dequeue QQ, enqueue unvisited neighbor: MM. Queue: [N,M][N, M].

    5. Dequeue NN, no unvisited neighbors. Queue: [M][M].

    6. Dequeue MM, enqueue unvisited neighbor: RR. Queue: [R][R].

    7. Dequeue RR.

    The sequence of visited nodes is P →\to O →\to Q →\to N →\to M →\to R, which is valid.

Therefore, option (D) is correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Graph Traversals previous year question is Q15 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Graph Traversals in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Graph Traversals PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Graph Traversals in GATE CSE

Graph Traversals has 16 GATE CSE PYQs across 12 papers from 2014 to 2026. 5 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2017 Set 2.

How GATE tests Graph Traversals

More from GATE CSE 2017 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 2 · Q15 · MCQ

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?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.