Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Algorithms
Algorithmsmedium

What is memoization and when does it help?

Tags
#memoization#dynamic-programming#cache
Back to categoryPractice quiz

Answer

Memoization caches results of a function for given inputs, so repeated calls reuse the cached value. It helps when you have overlapping subproblems (common in dynamic programming) and the same states are computed many times.

function fib(n: number, memo = new Map<number, number>()): number {
  if (n <= 1) return n;
  const cached = memo.get(n);
  if (cached !== undefined) return cached;

  const value = fib(n - 1, memo) + fib(n - 2, memo);
  memo.set(n, value);
  return value;
}

Related questions

Algorithms
What does the Floyd–Warshall algorithm compute and what is its complexity?
#graphs#shortest-path#floyd-warshall
Algorithms
Top-down vs bottom-up dynamic programming — what’s the difference?
#dynamic-programming#memoization#tabulation
Algorithms
What does Kadane’s algorithm solve?
#kadane#dynamic-programming#array
Algorithms
Greedy vs dynamic programming — what’s the key difference?
#greedy#dynamic-programming#optimization
Algorithms
What is Dynamic Programming?
#dynamic-programming#optimization#memoization
Next.js
App Router data fetching: what do `cache: 'no-store'` and `revalidate` change?
#nextjs#fetch#cache