Question

Consider the directed graph given below.

Directed graph on four vertices P, Q, R, and S

Which one of the following is TRUE?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2014 answer key

Solution

Find topological sorts of the directed acyclic graph by repeatedly selecting vertices with zero in-degree.

The graph has vertices {P,Q,R,S}\{P, Q, R, S\} and directed edges:

  • From PP: P→QP \to Q, P→RP \to R
  • From SS: S→QS \to Q, S→RS \to R
  • From RR: R→QR \to Q

In-degrees of vertices:

  • PP: 0 (no incoming edges)
  • SS: 0 (no incoming edges)
  • RR: 2 (incoming from PP and SS)
  • QQ: 3 (incoming from P,SP, S, and RR)

A topological ordering must place every vertex before all vertices it has edges to.

  • Either PP or SS can be chosen as the first vertex.
  • If PP is chosen first, remaining vertices have in-degrees: S:0,R:1,Q:2S: 0, R: 1, Q: 2. Thus SS must be second.
    After choosing SS, in-degrees become: R:0,Q:1R: 0, Q: 1. Thus RR must be third, followed by QQ.
    This yields the sequence: P,S,R,QP, S, R, Q.
  • If SS is chosen first, remaining vertices have in-degrees: P:0,R:1,Q:2P: 0, R: 1, Q: 2. Thus PP must be second.
    After choosing PP, RR is third, followed by QQ.
    This yields the sequence: S,P,R,QS, P, R, Q.

Both PSRQ and SPRQ are valid topological orderings, matching option C.

Final answer

C

Common trap

Thinking PQRSPQRS is a topological sort, but R→QR \to Q requires RR to precede QQ, which violates PQRSPQRS.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 1
Question
23 of 65, printed as CS Q.13
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.