Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A directed acyclic graph has the vertices A, F, J, K, P, R, S and the edges P→A, P→F, A→F, J→F, J→S, J→R, S→F. 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. K J P S R A F
- B. J K P A R S F
- C. J K P R S A F
- D. J S P K R A F
Correct answer: B. J K P A R S F
Kahn's algorithm that always takes the smallest available vertex (a min-heap) gives J K P A R S F. A FIFO queue gives J K P R S A F, which can differ, and a reverse-postorder DFS gives P K J S R A F.
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 counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 23. Two sequences of steps…
- Bellman–Ford is run from source S on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: S→E…
- Cities J, O, Q, V, X, Y are joined by roads with these travel costs: X–J 4, X–Q 5, X–Y 7, X–V 6, X–O 2, J–Q 8, J–Y 4, J–V 5, J–O 9, Q–Y…
- An undirected graph has the vertices C, E, F, L, U, X, Z and the edges L–C, C–U, X–L, E–C, Z–L, E–U, F–L, Z–C, E–Z, X–U. How many simple…
- An undirected graph has the vertices F, I, M, Q, T and the edges I–Q, Q–M, I–F, Q–F, I–T, T–Q, T–M, I–M, T–F. What is the minimum number…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…