Skip to content
Official PYQ · 2014

GATE CS 2014 Set 1 Q13 — Graph Traversals (BFS, DFS)

Explain with AI

Consider the directed graph below given. 

Which one of the following is TRUE?

Choose one option
View worked solution

Answer: C

The given directed graph has the following vertices and directed edges:

  • Vertices: P,Q,R,SP, Q, R, S
  • Edges: P→RP \to R, P→QP \to Q, S→RS \to R, S→QS \to Q, and R→QR \to Q

We can determine the topological orderings by analyzing the in-degrees of the vertices:

  • in-degree(P)=0\text{in-degree}(P) = 0
  • in-degree(S)=0\text{in-degree}(S) = 0
  • in-degree(R)=2\text{in-degree}(R) = 2 (incoming from PP and SS)
  • in-degree(Q)=3\text{in-degree}(Q) = 3 (incoming from PP, SS, and RR)

Since a topological sort must begin with a vertex of in-degree 00, we have two possible starting choices:

  1. Start with PP: After removing PP, the vertex SS is the only remaining vertex with an in-degree of 00. Removing SS leaves RR with an in-degree of 00, and finally QQ is left. This gives the sequence PSRQ.
  2. Start with SS: After removing SS, the vertex PP is the only remaining vertex with an in-degree of 00. Removing PP leaves RR with an in-degree of 00, and finally QQ is left. This gives the sequence SPRQ.

Thus, both PSRQ and SPRQ are valid topological orderings.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Graph Traversals (BFS, DFS) questions