IAE Academy

GATE 2024 DA Q.51: solution and answer

GATE 2024 · DAQ.51 · 2 marks · MSQ

Consider the directed acyclic graph (DAG) below. Which of the following is/are valid vertex orderings that can be obtained from a topological sort of the DAG?

GATE 2024 DA question 51: A DAG on seven labelled circular nodes P, R, Q, S, V, U, T.Tap to open full size
Figure from the GATE 2024 DA paper. It is part of the question.
Figure description

A DAG on seven labelled circular nodes P, R, Q, S, V, U, T. Directed edges: P -> Q, R -> Q (P and R sit at the top, both pointing down into Q); Q -> S and Q -> V (S on the lower left, V on the lower right); S -> U (U directly below S); V -> T (T directly below V). There are six edges in total.

  1. (A)

    P Q R S T U V

  2. (B)

    P R Q V S U T

  3. (C)

    P Q R S V U T

  4. (D)

    P R Q S V T U

Answer and solution

ANSWER

The valid topological orderings are (B) and (D).

Official answer: B, DSource: Official answer key, GATE 2024 DA (IISc Bengaluru)

  1. Read the edges from the figure: , , , , , .

  2. A topological order must place the tail of every edge before its head. So: and both come before ; comes before and ; comes before ; comes before .

  3. (A) P Q R S T U V: is at position 2 and at position 3, so is violated. Invalid. (It also puts before , violating .)

  4. (B) P R Q V S U T: (1) and (2) come before (3); comes before (4) and (5); (5) comes before (6); (4) comes before (7). Every edge is respected. Valid.

  5. (C) P Q R S V U T: is at position 2 and at position 3, so is violated. Invalid.

  6. (D) P R Q S V T U: (1) and (2) come before (3); comes before (4) and (5); (4) comes before (7); (5) comes before (6). Every edge is respected. Valid.

  7. So the valid topological orderings are (B) and (D).

KEY IDEA

An ordering is a valid topological sort exactly when, for every directed edge , appears before . Check each edge against each option's positions. The only freedom is the relative order of independent branches, here versus , and the chain versus the chain.

WATCH OUT FOR

Checking only that comes first and comes early, and missing that must also precede . Options (A) and (C) put right after , before . Another slip is forgetting that and are separate chains, so their order relative to each other is free.

From the GATE 2024 DA paper. Every question of this paper · Download the full paper · All 28 Graph algorithms questions, with notes

More Graph algorithms questions