Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q11 — Graph Traversals (BFS, DFS)

Explain with AI

Consider the following directed graph:

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

View worked solution

Answer: 6

The given directed graph consists of 5 vertices {a,b,c,d,e}\{a, b, c, d, e\} with the following directed edges:

  • a→ba \to b
  • a→ca \to c
  • b→db \to d
  • c→ec \to e

To find the number of topological orderings, we analyze the dependency constraints:

  1. Vertex aa has an in-degree of 0 and must always appear first in any topological sort.
  2. Once aa is placed, we are left with two independent parallel chains: b→db \to d and c→ec \to e.

The remaining 4 positions in the topological ordering must be filled by the elements of these two chains while preserving their internal order (bb before dd, and cc before ee).

The number of ways to choose 2 positions out of the remaining 4 for the chain b→db \to d is:

(42)=4×32=6\binom{4}{2} = \frac{4 \times 3}{2} = 6

Once these 2 positions are chosen, the order of bb and dd is fixed. The remaining 2 positions must be filled by cc and ee in their fixed order. Thus, there are exactly 6 different topological orderings.

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

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