Data Structures & AlgorithmsHardGATE CS
0/1 knapsack with capacity 18: items (weight, value) = (8, 39), (2, 16), (3, 24), (6, 38), (3, 36). What is the maximum total value?
- A. 114
- B. 113
- C. 115
- D. 216
Correct answer: C. 115
The DP over capacities gives 115. Greedy by value/weight ratio gives only 114 and greedy by value 113: 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
- Six sorted files have 8, 23, 33, 38, 42, 49 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- Kruskal's algorithm runs on the weighted undirected graph A–B (15), A–F (7), A–G (21), B–C (17), B–D (23), B–F (22), D–F (8), E–F (13)…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 131 nodes. How many…
- Six sorted files have 10, 12, 13, 21, 23, 42 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- Five matrices have dimensions 3×2 , 2×4 , 4×2 , 2×8 , 8×10. What is the minimum number of scalar multiplications needed to compute their…
- Keys 17, 35, 21, 81, 58, 30, 62, 57, 82, 93, 61 are inserted in that order into an empty BST. Then 58 is deleted and after that 35 is…