Data Structures & AlgorithmsModerateCognizant · Capgemini pattern
A topological ordering of a directed graph exists if and only if the graph is:
- A. Acyclic (a DAG)
- B. Connected
- C. Strongly connected
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A heap is stored in a 0-indexed array. What is the index of the parent of the element at index 10, and of its left child?
- Using the master theorem, what is the solution of T(n) = 2T(n/2) + n?
- In the activity selection problem (choose the most non-overlapping intervals), which greedy rule always gives an optimal answer?
- Why does the greedy method (best value-per-weight first) solve the fractional knapsack problem but not the 0/1 knapsack problem?
- How many edges does a complete undirected simple graph on 10 vertices have?
- What is the time to search for a word of length L in a trie that holds n words?