Data Structures & AlgorithmsHardGATE CS · ICPC regional
Directed acyclic graph on vertices A, B, C, D, E with edges A→C, A→E, E→B. 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. D A E C B
- B. A D C E B
- C. D A E B C
- D. A C D E B
Correct answer: D. A C D E B
Kahn's algorithm with a min-heap always takes the smallest available vertex and yields A C D E B. 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
- Distinct keys [6, 20, 4, 25, 16] are inserted, in the order given by the sequence [16, 25, 20, 6, 4], into an empty binary search tree…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–F (1), A–G (1), B–C (1), B–G (1), C–D (1), C–G (1), E–G (1)…
- Array A = [6, 7, 4, 1, 8, 8, 7] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→B (4), A→C…
- Array A = [2, 2, 4, 4, 1, 5, 2, 3, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: B–D (7), A–D (7), C–D (9), D–E (3), A–C (2)…