Data Structures & AlgorithmsHardGATE CS
0/1 knapsack with capacity 16: items (weight, value) = (9, 40), (3, 34), (2, 19), (7, 38), (7, 32). What is the maximum total value?
- A. 91
- B. 78
- C. 174
- D. 93
Correct answer: D. 93
The DP over capacities gives 93. Greedy by value/weight ratio gives only 91 and greedy by value 78: 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
- Using parts 1, 5, 6 (each any number of times), in how many ways can 9 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?
- In the DAG with edges A→B, A→G, B→D, D→G, E→A, E→B, E→C, E→D, E→F, E→G, G→C, how many distinct directed paths are there from E to C, and…
- A 5 × 5 grid is given row by row as .##.. / ..... / ....# / ...#. / .#... ('#' = wall). Moving one step up, down, left or right through…
- What is the minimum number of cuts needed to split 'madamimad' into pieces that are all palindromes?
- A binary min-heap is stored in a 0-indexed array [13, 33, 15, 35, 42, 23, 32]. Perform, in order: insert 6, delete-min, insert 60…
- The directed graph A→C (5), A→E (7), B→A (5), C→B (5), D→A (5), D→B (-6), E→C (9), E→D (7) has one negative edge but no negative cycle…