dynamic-programming

Dynamic Programming

Solves a problem by dividing into smaller sub-problems

Stores solution of sub-problems to avoid solving more than one once

Dynamic programming is a technique used to optimise a recursive solution that does repeated work by storing solution of sub-problems , avoiding to solve them more than once

Keep thinking of not doing repeated work

When to use?

Optimal substructure

  • What is it?

    A problem has a optimal substructure if :

    The optimal solution of problem can be calculated from optimal sub-problems

Overlapping sub-problems

  • What is it?

    A problem has a overlapping sub-problems if :

    During the recursive process of dividing into subproblems , solve the same sub-problems more than once

What is dynamic programming? - Inside code


Dynamic Programming Approaches

Top-down ( Memoization )

  • What is it ?

    Solve problems using by storing the results of recursively called functions

    • Why is it called the top down approach?

      Untitled

      Starts by trying to solve the initial problem if not solve sub-problems


Bottom-up ( Tabulation)

  • What is it ?

    Solve problems using by storing solutions of smaller subproblems to use to solve the main problem iteratively.

    Untitled

Multidimensional DP

1D DP - 1 variable

2D DP - 2 variable

Introduction to Multi-dimensional Dynamic Programming

Last updated