Question

Consider the following directed graph:

Directed acyclic graph with six vertices labeled a, b, c, d, e, and f. Directed edges are from a to b, a to d, b to c, d to e, c to f, and e to f. Node a is the sole source with in-degree 0, and node f is the sole sink with out-degree 0.
Directed Acyclic Graph with 6 Vertices

The number of different topological orderings of the vertices of the graph is _____.

Official answer and solution
Official answer
6
From
Official GATE 2016 answer key

Solution

Count topological sorts by identifying the fixed source and sink, and counting valid interleavings of the middle paths.

Analyze the given directed acyclic graph (DAG):

  • Vertices: {a,b,c,d,e,f}\{a, b, c, d, e, f\}
  • Directed edges: (a,b),(a,d),(b,c),(d,e),(c,f),(e,f)(a, b), (a, d), (b, c), (d, e), (c, f), (e, f)

Inspect vertex in-degrees and out-degrees:

  • Node aa has in-degree 0 and out-degree 2. It must be the very first vertex in every topological ordering.
  • Node ff has in-degree 2 and out-degree 0. It must be the very last vertex in every topological ordering.

The four middle vertices form two independent parallel directed chains:

  • Upper chain: b→cb \to c (vertex bb must appear before cc)
  • Lower chain: d→ed \to e (vertex dd must appear before ee)

In any valid topological sort, the sequence must have the form:

a,_,_,_,_,fa, \_, \_, \_, \_, f

where the 4 middle positions are filled with {b,c,d,e}\{b, c, d, e\} such that bb precedes cc and dd precedes ee.

The number of ways to interleave these two chains is the number of ways to choose 2 positions out of 4 for bb and cc (with bb in the earlier spot and cc in the later spot):

Total topological orderings=(42)=4!2!2!=244=6\text{Total topological orderings} = \binom{4}{2} = \frac{4!}{2! 2!} = \frac{24}{4} = 6

The 6 valid topological orderings are:

  1. a,b,c,d,e,fa, b, c, d, e, f
  2. a,b,d,c,e,fa, b, d, c, e, f
  3. a,b,d,e,c,fa, b, d, e, c, f
  4. a,d,b,c,e,fa, d, b, c, e, f
  5. a,d,b,e,c,fa, d, b, e, c, f
  6. a,d,e,b,c,fa, d, e, b, c, f
Final answer

6

Common trap

Permuting the 4 middle vertices arbitrarily (4!=244! = 24) without enforcing the ordering constraints within each chain.

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

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 1
Question
21 of 65, printed as CS Q.11
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.