GATE Computer ScienceHardGATE CSE · NIELIT
A DAG on vertices 0..5 has edges 0→2, 1→2, 1→3, 2→4, 3→4, 3→5, 4→5. How many distinct topological orderings does it have?
- A. 7
- B. 5
- C. 3
- D. 10
Correct answer: B. 5
Vertex 5 must come last (it follows 3 and 4 and everything reaches it); counting the valid orders of the other five vertices gives 5.
More Algorithms questions
- A binary search (loop while low ≤ high, mid = ⌊(low+high)/2⌋) runs on a sorted array of 1000 elements. The maximum number of loop…
- Keys 1..7 are inserted into an initially empty BST (no balancing) in some order. For how many of the 7! insertion orders does the…
- Keys 1..8 are inserted into an empty BST in each of the 8! possible orders. In how many orders is the resulting tree a single path (height…
- For X = "ABCBDAB" and Y = "BDCABA", how many DISTINCT strings are longest common subsequences of X and Y?
- An undirected weighted graph on vertices 0..6 has edges, written (u, v, weight): (0,1,2), (0,2,2), (1,2,2), (1,3,3), (2,3,3), (3,4,1)…
- A directed graph has edges S→A (4), S→B (2), B→A (−3), A→C (2), B→D (3), D→C (−5). Dijkstra's algorithm is run from S: each extracted…