Data Structures & AlgorithmsHardProduct-company MCQ pattern
0/1 knapsack, capacity 7. Items (weight, value): (1, 1), (3, 4), (4, 5), (5, 7). What is the maximum total value?
- A. 8
- B. 17
- C. 9
- D. 12
Correct answer: C. 9
Weights 3 + 4 = 7 give 4 + 5 = 9, the best fit; 5 + 1 gives only 8. Ratio-greedy takes (5, 7) then (1, 1) for 8, adding every item ignores the capacity (17), and the two most valuable items (7 + 5 = 12) weigh 9.
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
- Matrices A (10 × 20), B (20 × 30) and C (30 × 40) are to be multiplied. What is the minimum number of scalar multiplications?
- What is the length of the longest strictly increasing subsequence of [3, 10, 2, 1, 20, 4, 6, 7]?
- AVL tree: keys 30, 10, 20 are inserted in that order into an empty tree. What rebalancing happens, and what is the root afterwards?
- What is the minimum number of nodes in an AVL tree of height 4 (a single node has height 0)?
- How many different spanning trees does the complete graph K₄ have?
- How many times in total is fib called (including the first call) when fib(6) is evaluated? c int fib(int n) { if (n <= 1) return n; return…