Data Structures & AlgorithmsModerateCognizant · Capgemini pattern

A topological ordering of a directed graph exists if and only if the graph is:

  1. A. Acyclic (a DAG)
  2. B. Connected
  3. C. Strongly connected
  4. D. A tree

Correct answer: A. Acyclic (a DAG)

In a cycle every vertex would have to come before the next one around the cycle, which is impossible, and every DAG has at least one topological order. A strongly connected graph with more than one vertex always has a cycle.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic