Practice free →
HomeGATE CSEcomputerscienceAlgorithms › Topological sort is well-defined for

Topological sort is well-defined for

Aany undirected graph
Bany directed graph
Cdirected acyclic graphs (DAGs) only
Dgraphs with at least one negative edge weight
Answer & Solution
Correct answer: C. directed acyclic graphs (DAGs) only
Topological sort requires that all edges go forward in the ordering. A cycle would force each of its vertices to precede the others — impossible. So topological sort applies only to directed acyclic graphs. Both DFS-based and Kahn's algorithm detect cycles when they appear: DFS finds a back edge, Kahn's queue empties early.
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions