Cosmic Module
D
Qubits of DPK
January 16, 2026
Core DSA
UNBOUNDED KNAPSACK — ALL VERSIONS (JAVA)
Unbounded rule:
After
1️⃣ RECURSION (Brute Force)
java
QUBITS OF DPK
⏱ Complexity
- Time: Exponential
- Space: O(N) (recursion stack)
2️⃣ MEMOIZATION (Top-Down DP)
java
QUBITS OF DPK
⏱ Complexity
- Time: O(N × C)
- Space: O(N × C) + recursion stack
3️⃣ TABULATION (Bottom-Up DP)
java
QUBITS OF DPK
Key difference vs 0/1
plain text
QUBITS OF DPK
⏱ Complexity
- Time: O(N × C)
- Space: O(N × C)
4️⃣ 1D SPACE OPTIMIZED (MOST IMPORTANT)
java
QUBITS OF DPK
Why forward loop?
It allows the
⏱ Complexity
- Time: O(N × C)
- Space: O(C) ⭐
ONE-LINE DIFFERENCE (MEMORIZE)
plain text
QUBITS OF DPK
15-second interview summary
“Unbounded knapsack allows reusing items.
In recursion and memoization, we stay on the same index after picking.
In tabulation and 1D DP, we loop capacity forward to allow reuse.”