When to prefer memoization over tabulation

A DP has a state space of 10710^{7} possible states, but for a given input only about 500500 of them are actually reachable from the top-level query, and the dependency chains can be up to 10610^{6} states deep. Both top-down memoization and bottom-up tabulation give the same O(states)O(\text{states}) big-O in the worst case. Which single statement correctly identifies the right approach for this input and why?

Show hints (2)+
  1. Only ∼ ⁣500\sim\!500 of 10710^7 states are reachable - which method skips the rest?
  2. But 10610^6-deep recursion threatens the call stack - a fixable caveat, not a reason to switch.

Answer

Reveal answer →

Memoization - it computes only the ∼ ⁣500\sim\!500 reachable states, but the 10610^6-deep recursion must be made iterative or given a larger stack

Create a free account to see the full worked solution and track your progress.

Interview format: Market Maker, Options Trading

Related questions