What is DP?
Dynamic Programming is just an optimization over plain recursion. Whenever we see a recursive solution that repeatedly solves the same problems, we can optimize it using DP.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Master the core concepts of Overlapping Subproblems and Optimal Substructure that define Dynamic Programming.
Dynamic Programming is just an optimization over plain recursion. Whenever we see a recursive solution that repeatedly solves the same problems, we can optimize it using DP.
Like in Fibonacci, where Fib(2) is called multiple times. If we store the result of Fib(2) the first time, we never have to compute it again.
A problem has optimal substructure if an optimal solution can be constructed from optimal solutions of its subproblems. (e.g., Shortest Path).
Top-Down uses recursion + a memoization hash map. Bottom-Up uses iteration + a DP table (array). Both achieve the same time complexity.