Data Structures & AlgorithmsHardGATE CS · ICPC regional
The directed acyclic graph has the vertices A, I, L, P, Q, W and the arcs W→P, I→A, W→I, L→I, Q→A, L→W, L→Q, L→A. How many distinct directed paths go from L to A? A path is a sequence of consecutive arcs; a single arc counts as a path.
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: A. 4
Count with ways[x] = sum of ways[y] over arcs y→x, starting at ways[L] = 1 and processing vertices in a topological order. This gives 4 paths; using only paths of at most two arcs would give 3.
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 has the vertices B, G, S, T, Y and the edges S–B, G–S, S–Y, S–T, B–T, G–Y, B–Y. What is the minimum number of edges…
- A directed acyclic graph has the vertices A, B, K, S, X, Y and the edges B→K, B→S, B→Y, B→X, S→K, Y→S, Y→X. A topological order lists…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 are inserted in order into an empty BST. Then 30 is deleted, then 50 is deleted; a node with…
- The array [3, 9, 2, 1, 4, 5, 8] is converted to a max-heap by Floyd's bottom-up method, sifting down from the last parent to the root…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65, 36 are inserted in this order into an empty binary search tree. The post-order traversal of…
- Keys 40, 20, 10, 25, 30, 22, 50, 35, 45, 60, 55, 65 are inserted one by one into an initially empty AVL tree. The pre-order traversal of…