Data Structures & AlgorithmsVery hardGATE CS · Advanced
A directed acyclic graph has the vertices A–G and the arcs D→F, D→C, D→B, G→C, G→A, C→A, C→E, C→B. How many different topological orderings does it have?
- A. 560
- B. 74
- C. 66
- D. 60
Correct answer: C. 66
Count linear extensions by dynamic programming over subsets: the number of orderings ending with each available vertex is added up; the answer is 66.
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
- In a bipartite graph the left vertices are L1–L6 and the right vertices are R1–R6, with the edges L1–R3, L1–R5, L1–R6, L2–R3, L3–R2…
- Dijkstra's algorithm (a vertex is settled when removed from the priority queue and its distance is never changed afterwards) is run from A…
- A directed graph on the vertices A–E has the arcs C→B, C→A, B→C, B→E, B→A, D→E, E→B, E→A, A→C, A→B, A→D. Every vertex has equal in-degree…
- Every node of a binary tree has either 0 or 2 children. Its preorder traversal is W S M Q R P K Z T and its postorder traversal is Q R M K…
- A graph has the vertices A–G and the edges A–B, A–C, A–D, B–D, B–F, B–G, C–D, C–F, C–G, D–F, E–F. In how many ways can the vertices be…
- Floyd-Warshall is run on a directed graph with vertices 1-6 and arcs (weights): 1→2 (9), 1→3 (8), 1→4 (8), 1→5 (1), 2→5 (3), 2→6 (8), 3→1…