Data Structures & AlgorithmsHardGATE CS
0/1 knapsack with capacity 17: items (weight, value) = (9, 21), (6, 19), (3, 9), (7, 13), (3, 27). What is the maximum total value?
- A. 55
- B. 57
- C. 59
- D. 135
Correct answer: C. 59
The DP over capacities gives 59. Greedy by value/weight ratio gives only 55 and greedy by value 57: greedy is optimal only for the fractional version.
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
- Coins of denominations 1, 6, 9, 10 are available in unlimited supply. What is the minimum number of coins needed to make 33, and how many…
- For the string BBABCBCAB, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- With 3 identical eggs and at most 5 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 187 nodes. How many…
- The directed graph A→C (4), A→E (5), B→A (6), C→B (8), D→C (1), E→B (9), E→C (-6), E→D (2) has one negative edge but no negative cycle…
- Prim's algorithm starts at F on the weighted undirected graph A–C (28), A–D (6), A–F (3), A–G (7), B–C (14), B–F (26), C–D (21), C–E (19)…