CS: Dynamic Programming: Memoization and Tabulation
Solving overlapping subproblems with saved results
Solving overlapping subproblems with saved results
CS - Grade 9-12
- 1
In your own words, explain what dynamic programming is and name the two main properties a problem usually needs in order for dynamic programming to be useful.
- 2
A recursive Fibonacci function calls fib(n - 1) and fib(n - 2) until it reaches fib(0) or fib(1). Explain why this plain recursive version does repeated work.
- 3
For the Fibonacci sequence where fib(0) = 0 and fib(1) = 1, fill in the tabulation values from fib(0) through fib(7).
- 4
Compare memoization and tabulation. State one similarity and one difference between the two approaches.
- 5
The following pseudocode uses memoization: function fib(n): if n is in memo: return memo[n] if n <= 1: return n memo[n] = fib(n - 1) + fib(n - 2) return memo[n] If fib(6) is called with an empty memo, what final key-value pairs should be stored in memo for n from 2 through 6?
- 6
A student says, "Memoization always uses less memory than tabulation because it only computes what it needs." Explain why this statement is not always true.
- 7
You can climb a staircase by taking either 1 step or 2 steps at a time. Let ways(n) be the number of ways to climb n steps. Write the recurrence relation and base cases for this problem.
- 8
Using the staircase recurrence ways(n) = ways(n - 1) + ways(n - 2), ways(0) = 1, and ways(1) = 1, compute ways(2) through ways(5) using tabulation.
- 9
A coin change problem asks for the minimum number of coins needed to make a target amount using coin values 1, 3, and 4. Let dp[x] be the minimum number of coins needed for amount x. Write a recurrence for dp[x].
- 10
Using coins 1, 3, and 4 with dp[0] = 0, find the minimum number of coins needed to make amount 6. Show the best combination.
- 11
A longest common subsequence problem compares strings A = "ABC" and B = "AC". What is the length of the longest common subsequence, and what is one such subsequence?
- 12
For Fibonacci, explain how a tabulation solution can be changed from using an array of size n + 1 to using only constant extra space.
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 9-12 Worksheets
Linear Equations
Math · 8 problems
Cell Biology
Biology · 8 problems
Reading Comprehension
Language Arts · 8 problems
Historical Thinking & Evidence
Social Studies · 8 problems