What is Memoization?
Cache the result of a function call so repeated calls are instant.
Type a tool name, format or task
Cache the result of a function call so repeated calls are instant. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Cache the result of a function call so repeated calls are instant. Before computing, check whether the result is already in the cache. If it is, return it immediately. Otherwise compute it, store it and return it. Time complexity: O(n) instead of O(2ⁿ) for Fibonacci. Space complexity: O(n). useMemo, reselect, expensive derived values and any pure function called with the same input repeatedly.
Cache the result of a function call so repeated calls are instant.
Time: O(n) instead of O(2ⁿ) for Fibonacci. Space: O(n).
useMemo, reselect, expensive derived values and any pure function called with the same input repeatedly.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Recursive fib recomputes the same values again and again. Memoization stores each result so it is calculated once.
function fib(n, memo = {}) {if (n < 2) return n;if (memo[n] !== undefined) return memo[n];memo[n] = fib(n - 1, memo) + fib(n - 2, memo);return memo[n];}
Tip: use the arrow keys to step and the space bar to play or pause.