Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Memoized Fibonacci Lab
Dynamic Programming
Problem shape
Beginner
4
8
15
16
23
42
Core idea
Cache repeated recursive results so each state is solved once.
Step 1 / 5
Problem shape
Dynamic Programming Beginner
Memoized Fibonacci
Welcome to the Memoized Fibonacci algorithm lab. Cache repeated recursive results so each state is solved once. Use it when: Use as the simplest model for top-down dynamic programming. The time complexity is O(n), and the space complexity is O(n). The pseudocode is: fib(n) if n <= 1 return n if memo has n return memo[n] memo[n] = fib(n - 1) + fib(n - 2) return memo[n] As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n)
Space
O(n)
Pseudocode
fib(n)
if n <= 1 return n
if memo has n return memo[n]
memo[n] = fib(n - 1) + fib(n - 2)
return memo[n] 1.0x