Question
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:
- Directed edges:
Inspect vertex in-degrees and out-degrees:
- Node has in-degree 0 and out-degree 2. It must be the very first vertex in every topological ordering.
- Node 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: (vertex must appear before )
- Lower chain: (vertex must appear before )
In any valid topological sort, the sequence must have the form:
where the 4 middle positions are filled with such that precedes and precedes .
The number of ways to interleave these two chains is the number of ways to choose 2 positions out of 4 for and (with in the earlier spot and in the later spot):
The 6 valid topological orderings are:
6
Permuting the 4 middle vertices arbitrarily () 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.