Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
A DAG has edges A→B, B→C, B→D, C→E, A→F, A→D, D→F. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently available with in-degree 0), what is the topological order?
- A. ABCDEF
- B. FEDCBA
- C. EBDFAC
- D. ACBDEF
Correct answer: A. ABCDEF
Repeatedly remove the smallest-labelled vertex with in-degree 0 and decrement its neighbours' in-degree, giving ABCDEF.
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
- Keys 74, 72, 41, 18, 95, 79, 69 are inserted in this order into an empty BST. What is the preorder traversal?
- An AVL tree node has left subtree height 4 and right subtree height 1. What must happen after this imbalance is detected?
- Keys 77, 23, 72, 58, 94, 42, 92 are inserted in this order into an empty BST. What is the postorder traversal?
- In the undirected graph with edges A–B:14, A–C:4, B–D:8, C–E:11, D–F:12, C–F:9, what is the shortest-path distance from A to C?
- An undirected graph has edges (u–v: weight) A–B:8, B–C:11, C–D:6, C–E:3, A–C:6. What is the weight of its minimum spanning tree?
- A DAG has edges A→B, A→C, A→D, A→E, D→E. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently…