Data Structures & AlgorithmsHardGATE CS (PYQ pattern)
A DAG on vertices 1..6 has edges 1→3, 2→3, 3→4, 3→5, 2→6 and 5→6. How many distinct topological orderings does it have?
- A. 8
- B. 5
- C. 6
- D. 4
Correct answer: C. 6
Vertices 1 and 2 must precede 3 (2 orders), then 3 precedes 4 and 5, and 5 precedes 6, with 2 also before 6. Enumerating all linear extensions gives 6 valid orderings.
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 weighted digraph has edges S→A (2), S→B (5), A→C (4), B→A (−4), B→C (1) and C→T (1). Textbook Dijkstra (a vertex's distance is final…
- An undirected graph on vertices a-f has edges ab(1), bc(2), ac(2), cd(3), bd(3), de(1), ce(4), ae(4), ef(2), df(2). How many distinct…
- A directed graph has the vertices A, B, C, D, E, F, G, H, I and the arcs A→E, B→E, B→F, D→C, E→B, E→C, G→E, G→I, H→B, H→F, I→C, I→H. What…
- An undirected connected graph has the vertices A–J and the edges A–H, B–E, C–I, C–J, D–E, E–G, E–I, F–I, G–J, H–I, H–J, I–J. How many…
- A graph has the vertices A–F and the edges A–B, A–C, B–C, B–D, C–D, C–E, D–E, D–F, E–F, A–F. How many distinct spanning trees does it have?
- Floyd's bottom-up build-heap (sift-down from the last internal node back to the root) is applied to the array [55, 25, 49, 27, 3, 17, 33…