Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed acyclic graph on vertices 0 to 7 has these directed edges (u → v): 0→4, 1→3, 1→6, 2→0, 3→0, 6→2, 6→5, 7→0. Among all topological orders, which one is the lexicographically smallest (compare the sequences of vertex numbers from the left)?
- A. 7 1 6 5 3 2 0 4
- B. 1 7 3 6 2 5 0 4
- C. 1 3 6 2 5 7 0 4
- D. 7 1 6 5 2 3 0 4
Correct answer: C. 1 3 6 2 5 7 0 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
- A directed acyclic graph on vertices 0 to 7 has these directed edges (u → v): 0→6, 1→4, 1→6, 1→7, 2→6, 4→0, 7→2, 7→4, 7→5, 7→6. Among all…
- A directed acyclic graph on vertices 0 to 6 has these directed edges (u → v): 0→3, 0→4, 0→5, 1→3, 2→1, 2→4, 5→1, 5→6. Among all…
- A directed acyclic graph on vertices 0 to 6 has these directed edges (u → v): 2→0, 2→4, 2→5, 4→0, 5→0, 5→3, 6→5. Among all topological…
- A directed acyclic graph on vertices 0 to 6 has these directed edges (u → v): 0→4, 0→5, 0→6, 1→4, 2→4, 3→1, 6→1, 6→2, 6→4, 6→5. Among all…
- A directed acyclic graph on vertices 0 to 6 has these directed edges (u → v): 0→2, 0→6, 1→4, 2→3, 2→5, 5→1, 6→3. Among all topological…
- A directed acyclic graph on vertices 0 to 5 has these directed edges (u → v): 0→2, 0→3, 0→5, 1→2, 5→1. Among all topological orders, which…