Data Structures & AlgorithmsHardGATE CS
In the DAG with edges B→E, C→A, C→G, D→A, D→B, D→C, D→F, D→G, F→A, F→B, F→C, how many distinct directed paths are there from D to G, and how many edges does the longest one have?
- A. 3 paths, longest 2
- B. 3 paths, longest 3
- C. 4 paths, longest 3
- D. 5 paths, longest 3
Correct answer: B. 3 paths, longest 3
Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(G) = 1, giving 3; the same order with max(1 + len(v)) gives the longest path, 3 edges.
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 DAG on vertices A–G has edges B→A, B→D, B→F, E→C, F→A, F→E, G→A, G→C. What order does Kahn's algorithm that always removes the…
- A 3-ary max-heap is stored in a 0-indexed array (children of i at 3i + 1 … 3i + 3): [51, 43, 34, 20, 27, 18, 3, 8, 17, 10]. After…
- What is the minimum number of edges m such that EVERY simple undirected graph with 9 vertices and m edges is guaranteed to be connected?
- In the grid 01210 / 11111 / 11121 / 01111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- A binary tree with distinct labels has INORDER E D I C A G H B F and LEVEL-ORDER I D H E G B C F A. What is its postorder traversal?
- The boolean expression F & T | T & T (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…