Which methods can reduce memory use in dynamic programming?
Exercise
- Compress a 2D table into a single working row
- Keep only the required part of the table
- Recurse without memoization
- Replace dynamic programming with a greedy algorithm
- Keep only a few recent values
- Use sparse storage
Solution
Rolling storage requires limited dependencies. Sparse storage helps when few states are reachable.
In a grid, one row may suffice: take the untouched cell for the value above and the updated neighbour for the value to the left. Fibonacci needs just two earlier numbers. If only s states of a large table are reachable, store only those state-value entries. This accounts for choices 1, 2, 5 and 6.
r × c → c. G(r,c) = G(r−1,c) + G(r,c−1). F(i) = F(i−1) + F(i−2). s ≪ r × c → O(s).
First identify what the next transition reads. A cell may be overwritten only after its old value has been used for the last time. Recovering an entire path can require extra information even when computing its value does not.
Platforms
- MAXIMUM
