Embed presentation
Download as PDF, PPTX










This document discusses the knapsack problem in computer science and provides solutions using dynamic programming. It describes the 0-1 knapsack problem, where items are indivisible and must be fully included or excluded, and the fractional knapsack problem, where items can be partially included. For fractional knapsack, it presents a greedy algorithm that sorts by value/weight ratio and fills the knapsack. For 0-1 knapsack, it presents a recursive solution and suggests using a 2D DP table to store intermediate results with complexity of O(nW) where n is items and W is capacity. Code examples are provided for both problems.









