Data Structures & AlgorithmsHardGATE CS · ICPC regional
The directed acyclic graph has the vertices C, I, J, R, Y, Z and the arcs C→R, Z→J, R→Y, I→Z, Z→Y, C→Y, Z→C, Y→J, I→C, I→J, Z→R, R→J. How many distinct directed paths go from I to J? A path is a sequence of consecutive arcs; a single arc counts as a path.
- A. 11
- B. 12
- C. 3
- D. 2
Correct answer: A. 11
Count with ways[x] = sum of ways[y] over arcs y→x, starting at ways[I] = 1 and processing vertices in a topological order. This gives 11 paths; using only paths of at most two arcs would give 2.
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 four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P3–Q1, P3–Q5, P1–Q5, P2–Q3. What is…
- A connected undirected graph has the vertices A, E, G, J, P, Q, Z and the edges Z–P, Z–J, Z–E, Z–A, P–J, P–G, J–E, A–Q. How many bridges…
- An undirected graph has the vertices A, B, J, Q, Y and the edges Q–J, Q–B, Y–J, Y–B, A–J. A walk may repeat vertices and edges. How many…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 1) if n % 2 == 0: f(n - 3) How many times is f called in total…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 24. Two sequences of steps…