Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

## Dynamic Programming

Last Updated: Nov 17, 2023
Go to Problems
Dynamic Programming
Complete all the problems in this Topic to unlock a badge
Completed
Go to Problems
Contents

# Characteristics of Dynamic Programming

Before moving on to approaches to solve a DP problem, let us have a look at the characteristics of a problem upon which we can apply the DP technique.

We can apply DP technique to those problems that exhibit the below 2 characteristics:

### 1. Optimal Substructures

• Any problem is said to be having optimal substructure property if its overall optimal solution can be evaluated from the optimal solutions of its subproblems.
• Consider the example of Fibonacci Numbers.
• We know that a nth Fibonacci number (Fib(n)) is nothing but sum of previous 2 fibonacci numbers, i.e: `Fib(n) = Fib(n-1) + Fib(n-2)`.

• From the above equation, we can clearly deduce that a problem of size ‘n’ has been reduced to subproblems of size ‘n-1’ and ‘n-2’.

• Hence, we can say that Fibonacci numbers have the optimal substructure property.

### 2. Overlapping Subproblems

• Subproblems are basically the smaller versions of an original problem. Any problem is said to have overlapping subproblems if calculating its solution involves solving the same subproblem multiple times.
• Let us take the example of finding nth Fibonacci number. Consider evaluating Fib(5). As shown in the breakdown of steps shown in the image below, we can see that Fib(5) is calculated by taking sum of Fib(4) and Fib(3) and Fib(4) is calculated by taking sum of Fib(3) and Fib(2) and so on. Clearly, we can see that the Fib(3), Fib(2), Fib(1) and Fib(0) has been repeatedly evaluated. These are nothing but the overlapping subproblems.
``Note: It is important for a problem to have BOTH the above specified characteristics in order to be eligible to be solved using DP technique.``

## Dynamic Programming Problems

0/9
2D string DP
0/9
Simple array DP
0/3
Greedy OR DP
0/11
DP tricky
0/2
tree DP
0/14
Matrix DP
0/5
Suffix / prefix DP
0/3
Derived DP
0/4
Knapsack
0/1
DP
0/1
0/1
DP optimized backtrack
0/2
Multiply DP
0/2
Breaking words
Topic Bonus
Bonus will be unlocked after solving min. 1 problem from each bucket

## Video Courses By

View All Courses
Excel at your interview with Masterclasses Know More
Certificate included
What will you Learn?
Free Mock Assessment
Fill up the details for personalised experience.
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
*Enter the expected year of graduation if you're student
Current Employer
Company Name
College you graduated from
College/University Name
Job Title
Job Title
Software Development Engineer (Backend)
Software Development Engineer (Frontend)
Software Development Engineer (Full Stack)
Data Scientist
Android Engineer
iOS Engineer
Devops Engineer
Support Engineer
Research Engineer
Engineering Intern
QA Engineer
Co-founder
SDET
Product Manager
Product Designer
Backend Architect
Program Manager
Release Engineer