← All questions
RareProgramming

What is caching a subproblem’s result for later calls called?

Short answer
Memoization

Exercise

  1. Tabulation
  2. Memoization
  3. Greedy search
  4. Exhaustive search
  5. Merge sort

Solution

A later call with the same arguments uses the cached result.

Memoization stores a result under a key, for example the index of a Fibonacci number. The first call computes F(3) and stores two. When a different branch requests F(3), it gets the value immediately without expanding its children again.

F(5) → F(4) → F(3) = 2; cache[3] ← 2. F(5) → F(3) → cache[3] = 2.

A state must uniquely specify the remaining subproblem. Different routes through the computation that reach the same state can reuse the same previously computed value.

Dynamic programming

Platforms

  • MAXIMUM

Download now and try it for free on your own tasks!

10 15 free credits • No credit card required
Version: Loading…

Choose the Windows app or the Chrome extension with phone controls.