Knapsack
Everything on SkillVeris tagged Knapsack — collected across the glossary, study notes, blog, and cheat sheets.
10 resources across 2 libraries
Study Notes(2)
Interview Questions(8)
Greedy vs Dynamic Programming: What is the Difference?
Greedy algorithms make the locally optimal choice at each step and never reconsider it, while dynamic programming explores overlapping subproblems and combines…
0/1 Knapsack Problem: How Would You Solve It?
The 0/1 knapsack problem is solved with dynamic programming: build a table dp[i][w] representing the best value achievable using the first i items within capac…
How Do You Solve the Subset Sum Problem?
Subset sum asks whether some subset of a given set of numbers adds up exactly to a target value, solved with a 2D (or space-optimized 1D) dynamic programming t…
How Do You Solve Partition Equal Subset Sum?
Partition equal subset sum asks whether an array can be split into two subsets with equal totals, which is only possible if the overall sum is even, and then r…
How Do You Prove a Greedy Algorithm is Correct?
Greedy algorithm correctness is typically proven with the exchange argument (show any optimal solution can be transformed into the greedy solution without losi…
How Does Greedy Choice Relate to Optimal Substructure?
A greedy algorithm only produces a globally optimal solution when a problem has both the greedy-choice property — a locally optimal choice at each step leads t…
How Do You Optimize Space in Dynamic Programming?
Dynamic programming space is optimized by noticing that a DP table row (or diagonal) usually only depends on the immediately preceding row, so you can replace…
What is State Space Reduction in Dynamic Programming?
State space reduction is the technique of shrinking the number of distinct states a dynamic programming solution must track — by dropping redundant dimensions,…