Data Structures & AlgorithmsHardGATE CS · ICPC regional
Directed acyclic graph on vertices A, B, C, D, E, F with edges A→F, A→C, A→E, F→D, B→E, D→C. Among all topological orderings (every edge goes from earlier to later in the order), which one is lexicographically smallest when compared letter by letter? Give it as letters separated by spaces.
- A. B A F D E C
- B. B A F E D C
- C. A B E F D C
- D. A B F E D C
Correct answer: C. A B E F D C
Kahn's algorithm with a min-heap always takes the smallest available vertex and yields A B E F D C. A FIFO queue or reverse DFS postorder gives valid orders that are not lexicographically 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
- Directed acyclic graph on vertices A, B, C, D, E, F with edges B→D, A→F, A→E, D→E, F→C. Among all topological orderings (every edge goes…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–C (6), A–D (6), B–C (1), B–D (5), C–E (4), D–E (4). Among all…
- A 6 × 6 grid (rows top to bottom, '#' = filled, '.' = empty): ...... / ..#... / .#.### / ....#. / #...## / .#..#.. Two filled cells belong…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (9), A–D (7), A–F (7), B–D (5), C–E (9), D–E (5), D–F (7), E–F (3)…
- Undirected weighted graph on vertices A, B, C, D with edges A–C (1), A–D (1), B–C (3), B–D (1), C–D (1). How many distinct minimum…
- Directed weighted graph on vertices A, B, C, D with edges (u→v, w): C→A (2); D→B (1); C→D (7); B→A (5); B→D (5); A→B (8); D→A (3); C→B…