0% found this document useful (0 votes)
48 views

Dynamic Programmingpdf

Dynamic programming is a technique to solve problems by breaking them into sub-problems, solving each sub-problem only once, and storing the solutions for later use. There are two approaches: memoization solves from the extreme state to the base state, storing solutions; tabulation solves from the base state to the extreme state. Dynamic programming can optimize recursive solutions that have repeated sub-problem calls by reusing stored solutions rather than recomputing them.

Uploaded by

Niloy Barmon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Dynamic Programmingpdf

Dynamic programming is a technique to solve problems by breaking them into sub-problems, solving each sub-problem only once, and storing the solutions for later use. There are two approaches: memoization solves from the extreme state to the base state, storing solutions; tabulation solves from the base state to the extreme state. Dynamic programming can optimize recursive solutions that have repeated sub-problem calls by reusing stored solutions rather than recomputing them.

Uploaded by

Niloy Barmon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Dynamic Programming - 1

- Karun Karthik

Contents

0. Introduction
1. Climbing Stairs
2. Fibonacci Number
3. Min Cost Climbing Stairs
4. House Robber
5. House Robber - II
6. Nth Tribonacci Number
7. 0-1 Knapsack
8. Partition Equal Subset Sum
9. Target Sum
10. Count no of Subsets with given Difference
11. Delete and Earn
12. Knapsack with Duplicate Items
13. Coin Change - II
14. Coin Change
15. Rod cutting

https://www.linkedin.com/in/karun-karthik
Dynamic programming is a technique to solve problems by breaking it down into a colle
ction of sub-problems, solving each of those sub-problems just once and storing these
solutions inside the cache memory in case the same problem occurs the next time.

Dynamic Programming is mainly an optimization over plain recursion .


Wherever we see a recursive solution that has repeated calls for same inputs, we can o
ptimize it using Dynamic Programming.
This simple optimization reduces the time complexities from exponential to polynomial.

There are two different ways to store our values so that they can be reused at a later i
nstance. They are as follows:
1. Memoization or the Top Down Approach.
2. Tabulation or the Bottom Up approach.

In Memoization we start from the extreme state and compute result by using values th
at can reach the destination state i.e the base state.

In Tabulation we start from the base state and then compute results all the way till the
extreme state.

Note: To store the intermediate results we can use Array, Matrix, Hashmap etc., all we
need is data storage and retrieval with a specific key.

How to find the use case of Dynamic Programming?

You can use DP if the problem can be,


1. Divided into sub-problems
2. Solved using a recursive solution
3. Containing repetitive sub-problems

https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik
https://www.linkedin.com/in/karun-karthik

You might also like