Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→G (4), B→E (1), B→G (5), D→E (3), E→F (4). What is the largest total weight of any directed path (one or more edges) in this graph?
- A. 5
- B. 2
- C. 7
- D. 17
Correct answer: C. 7
A DP over vertices in topological order gives a heaviest path of weight 7. Counting the edges of that path, or summing every weight, gives other numbers.
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
- Directed weighted graph on vertices A, B, C, D with edges C→B (-4); C→A (-1); A→C (1); D→A (-4); A→D (-2); C→D (0). Source A. Run…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–E (1), B–D (1), B–E (1), C–H (1), D–G (1), D–H (1), E–F (1)…
- Array [12, 23, 8, 18, 15, 14, 26, 13] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the…
- Coins of denominations [11, 9, 8, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 28?…
- Distinct words ['caab', 'ac', 'aa', 'c', 'baab', 'bbb', 'bbca'] are inserted into an empty trie (one node per character, shared prefixes…
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (2, 5) and must reach (0, 0) (as (row, column)). A knight…