Data Structures & AlgorithmsHardGATE CS · Product-company placement
0/1 knapsack with capacity 18: items (weight, value) = (2, 25), (5, 31), (8, 37), (4, 22), (4, 27). What is the maximum total value?
- A. 105
- B. 111
- C. 95
- D. 225
Correct answer: B. 111
The DP over capacities gives 111. Greedy by value/weight ratio gives only 105 and greedy by value 95: 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
- Keys 78, 54, 58, 22, 55, 70, 25, 12, 39, 86 are inserted into an empty AVL tree (giving preorder 58, 25, 22, 12, 54, 39, 55, 78, 70, 86)…
- DFS runs on the directed graph with adjacency lists A: BDF; B: FG; C: ABE; D: G; E: –; F: D; G: A, starting at A, scanning lists in the…
- The directed graph A→C (5), A→D (4), A→E (7), B→D (2), C→B (4), C→D (1), D→E (7), E→C (-5) has one negative edge but no negative cycle…
- A binary min-heap is stored in a 0-indexed array [2, 19, 33, 58, 25, 35, 53]. Perform, in order: insert 36, insert 8, delete-min…
- Keys 78, 77, 48, 42, 39, 27, 67, 23, 57 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- Lectures occupy half-open intervals [start, end): [0, 3), [0, 7), [3, 7), [4, 12), [8, 12), [10, 16), [12, 18), [19, 27). A lecture ending…