Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
A directed acyclic graph has the vertices E, N, O, S, U, V, Z and the edges Z→S, N→O, U→V, U→N, U→O, E→V, E→S. 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. Z U N O E V S
- B. E U N O V Z S
- C. Z U E V N O S
- D. Z U E N V O S
Correct answer: B. E U N O V Z S
Kahn's algorithm that always takes the smallest available vertex (a min-heap) gives E U N O V Z S. A FIFO queue gives E U Z N V S O, which can differ, and a reverse-postorder DFS gives Z U N O E V S.
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
- An undirected graph on 6 vertices has the edges I–S, I–F, I–W, I–Q, I–K, S–F, S–K, F–K. How many simple paths (no repeated vertex) go from…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): X–Z (14), X–S (12), V–Z (30), S–Z (4), V–S…
- Consider this function: python def g(n): if n < 2: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 3) - 1 What value does…
- A connected undirected graph has the vertices F, H, I, M, O, V and the edges F–M, F–I, F–O, M–V, M–H, H–I. How many bridges does it have…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 10. Two sequences of steps…
- An undirected graph has the vertices C, G, I, K, N, W, Y and the edges C–Y, C–I, C–W, C–K, Y–I, Y–W, Y–K, N–I, N–W, G–K, I–K, W–K. What is…