Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
A DAG has edges A→B, A→C, B→D, C→E, A→D, B→C. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently available with in-degree 0), what is the topological order?
- A. DBECA
- B. EDCBA
- C. ABCDE
- D. ACBDE
Correct answer: C. ABCDE
Repeatedly remove the smallest-labelled vertex with in-degree 0 and decrement its neighbours' in-degree, giving ABCDE.
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
- What is the time complexity of searching for a word of length m in a trie that stores n words, independent of n?
- An undirected graph has adjacency lists A:BCEF B:AD C:ADF D:BCF E:A F:ACD. Neighbours are always explored in alphabetical order. Which is…
- An undirected graph has edges (u–v: weight) A–B:14, A–C:13, C–D:14, B–E:11, C–E:4, B–D:3. What is the weight of its minimum spanning tree?
- An undirected graph has adjacency lists A:B B:ACGH C:BDFG D:CE E:D F:C G:BC H:B. Neighbours are always explored in alphabetical order…
- Keys 47, 48, 97, 84, 52, 82, 34, 75 are inserted in this order into an empty BST. What is the height of the tree (edges on the longest…
- In the undirected graph with edges A–B:13, B–C:6, C–D:4, B–E:7, E–F:2, A–G:14, C–E:7, A–D:8, what is the shortest-path distance from A to B?