Back to the 2024 paper

Module 3: Graph and Tree Algorithms

20242m

Topological sorting is only possible in:
(i) Undirected Graphs
(ii) Trees
(iii) Directed Acyclic Graphs
(iv) Weighted Graphs

Worked SolutionAI Assisted

Answer: (iii) Directed Acyclic Graphs (DAGs)

Explanation:

  • Topological sorting is a linear ordering of vertices such that for every directed edge u→vu \to v, uu appears before vv.
  • Such ordering exists iff the graph has no directed cycle. If a cycle exists, no linear extension can satisfy all precedence constraints.
  • Undirected graphs have no direction → concept not defined (except trivial cases). Trees (when oriented as DAG) can be topologically sorted, but not all trees as undirected structures.
  • Weighted vs. unweighted is irrelevant; only acyclicity matters.

Algorithm: DFS post-order reversed or Kahn's BFS with indegree queue, both O(V+E)O(V+E).

Correct choice: (iii)

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.