Question Bank

Dynamic Programming Warm-Up

Difficulty: Easy

Memoization, tabulation, and writing transitions for classic 1D DP. Code stems are Python.

Question Bank
/

Dynamic Programming Warm-Up

Dynamic Programming Warm-Up

Memoization, tabulation, and writing transitions for classic 1D DP. Code stems are Python.

Question Bank
Easy
Python
3 questions
dynamic-programming
memoization
fundamentals
quiz

426 views

12

Implement fib(n) two ways: top-down with memoization and bottom-up with tabulation. Compare their space cost.

Examples

Example 1:

Input: n = 10 (using both fib_memo and fib_tab)
Output: 55 from both versions
Explanation: Both are O(n) time. Memo uses O(n) space for the dict plus the recursion stack; tabulation uses O(n) for the array and O(1) stack. Dropping tabulation to O(1) by tracking only the last two values is a one-line tweak.