Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed acyclic graph on vertices 0 to 7 has these directed edges (u → v): 1→4, 1→5, 3→0, 3→4, 3→5, 5→2, 6→0, 6→1, 7→4. Among all topological orders, which one is the lexicographically smallest (compare the sequences of vertex numbers from the left)?
- A. 7 6 3 1 5 2 4 0
- B. 7 6 3 1 5 4 2 0
- C. 3 6 7 0 1 4 5 2
- D. 3 6 0 1 5 2 7 4
Correct answer: D. 3 6 0 1 5 2 7 4
Always taking the smallest currently available vertex (Kahn's algorithm with a min-heap) gives the lexicographically smallest topological order. A FIFO queue or a reversed DFS finish order gives valid orders that are not the smallest.
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
- An unweighted undirected connected graph on vertices 0 to 6 has edges 0-1, 0-2, 0-3, 0-5, 1-2, 1-4, 1-5, 1-6, 2-3, 2-5, 5-6. How many…
- An unweighted undirected connected graph on vertices 0 to 5 has edges 0-1, 0-2, 0-4, 0-5, 1-2, 1-3, 1-4, 1-5, 2-3, 2-4, 3-5. How many…
- An unweighted undirected connected graph on vertices 0 to 7 has edges 0-1, 0-2, 1-4, 1-5, 2-3, 2-4, 2-6, 2-7, 3-4, 3-5, 3-7, 6-7. How many…
- An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-2, 0-3, 1-2, 1-3, 1-4, 2-3, 2-4, 3-4. How many different…
- An unweighted undirected connected graph on vertices 0 to 7 has edges 0-1, 0-2, 0-3, 0-4, 0-5, 1-5, 1-6, 2-3, 2-4, 3-5, 3-6, 4-5, 6-7. How…
- An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-3, 0-4, 1-2, 1-3, 1-4, 2-3, 2-4, 3-4. How many different…