Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A directed acyclic graph has the vertices D, E, I, Q, R, U, Z and the edges D→R, D→E, Z→D, Z→R, Z→Q, Z→E, R→U, Q→D, I→D. A topological order lists every vertex once so that each edge goes from an earlier to a later vertex. Which topological order is lexicographically smallest when read as a sequence of letters?
- A. I Z Q D R E U
- B. Z I Q D R E U
- C. I Z Q D E R U
- D. I Z Q D R U E
Correct answer: C. I Z Q D E R U
Kahn's algorithm that always takes the smallest available vertex (a min-heap) gives I Z Q D E R U. A FIFO queue gives I Z Q D E R U, which can differ, and a reverse-postorder DFS gives Z Q I D R U E.
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 graph has the vertices H, J, M, T, X, Y and the arcs M→T, M→X, T→X, J→Y, X→Y, Y→T, Y→J. How many strongly connected components…
- A tree has the vertices D, E, I, L, O, P, Q, T, W and the edges T–D, D–L, L–Q, Q–E, T–I, E–O, T–P, D–W. A centroid is a vertex whose…
- The directed acyclic graph has the vertices E, H, J, K, S, T, V, W and the arcs W→E, S→K, J→H, V→H, J→K, V→W, W→K, E→H, J→T, T→E, V→S…
- Grid with 3 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .GG G.. ... Each step, which is a move to…
- A directed acyclic graph has the vertices M, Q, U, V, X, Y, Z and the arcs M→Y, M→Q, M→V, U→Y, U→Z, U→V, Y→Q, Y→Z, Y→V, Q→Z, Q→X, Z→X…
- A bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P3–Q2, P2–Q4, P1–Q5, P3–Q4, P2–Q1, P3–Q5. What is…