AI engineering glossary · Data structures algorithms
What is knapsack problem?
Knapsack problem (also called 0/1 knapsack): An optimisation problem: given items with weights and values and a bag with a weight limit, choose items to maximise total value without exceeding the limit. The 0/1 version is solved by dynamic programming in O(n*W) time.
Knapsack problem: an example
With capacity 5 kg and items (2 kg, ₹30), (3 kg, ₹40), (4 kg, ₹50), the best choice is the first two items for ₹70.
Related terms
More Data structures algorithms terms
- Knuth-Morris-Pratt algorithm
- Kruskal's algorithm
- Linear search
- Linked list
- Load factor
- Longest common subsequence
- Longest increasing subsequence
- LRU cache
Where you learn it
Knapsack problem is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.