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