×
Home Discussions Write at Opengenus IQ
×
  • DSA Cheatsheet
  • HOME
  • Track your progress
  • Deep Learning (FREE)
  • Join our Internship 🎓
  • RANDOM
  • One Liner

Dynamic Programming (DP)

Dynamic Programming is an algorithmic technique in which the key idea is to store the values of smaller problems such that in case, the value is required again, it will return the value instead of recomputing. This works in problems which can be broken into smaller problems and smaller problems are encountered multiple times. When applicable, dynamic programming can reduced the time complexity greatly

Algorithms

Longest Palindromic Substring using Dynamic Programming

In this article, we have explored the longest palindromic substring problem for which brute force takes O(N^3) time while a Dynamic Programming approach takes O(N^2) time.

K. Sai Drishya K. Sai Drishya
Algorithms

Number of ways to reach a given number using increments of 1 and 2

The problem we will try to solve is to find the Number of ways to reach a given number (or a score in a game) using increments of 1 and 2 with consecutive 1s and consecutive 2s allowed. This is solved in linear time O(N) using Dynamic Programming.

K. Sai Drishya K. Sai Drishya
Algorithms

Find the Longest Increasing Odd Even Subsequence

In this problem, we have formulated an algorithm to find the Longest Increasing Odd Even Subsequence. Brute force approach takes exponential time O(2^N) but a Dynamic Programming approach takes O(N^2) time.

Shubham Kumar Shubham Kumar
Algorithms

Find the Longest Common Increasing Subsequence

In this problem, we have formulated an algorithm to find the Longest Common Increasing Subsequence. Brute force approach takes exponential time but a Dynamic Programming approach takes O(N^2) time.

Shubham Kumar Shubham Kumar
Algorithms

Maximum product cutting problem

In Maximum product cutting problem. we are given a rod of length N which we need to cut into small pieces such that the product of the length of the pieces is maximum. This is similar to the Rod Cutting problem and can be solved using Dynamic Programming.

K. Sai Drishya K. Sai Drishya
Algorithms

Find the number of subsets with given Bitwise OR value

We are given an array of size N and a value M, we have to find the number of subsets in the array having M as the Bitwise OR value of all elements in the subset. This can be solved using Dynamic Programming in polynomial time.

Siddharth Agarwal Siddharth Agarwal
Algorithms

Find minimum number of deletions to make a string palindrome

We need to find the minimum number of characters to be deleted in a string to make it a palindrome. This can be done in O(N^2) time with the help of Dynamic Programming approach of Longest Palindromic Subsequence.

Abhiram Reddy Duggempudi Abhiram Reddy Duggempudi
Algorithms

Longest Common Subsequence

In this problem, we solved the Longest Common Subsequence problem using Dynamic Programming which takes O(N*M) time while a brute force approach takes O(2^N) time

Ashutosh Singh Ashutosh Singh
Algorithms

Longest Common Substring in two strings

In this problem, we explored a Dynamic Programming approach to find the longest common substring in two strings which is solved in O(N*M) time. Brute force takes O(N^2 * M) time.

Ashutosh Singh Ashutosh Singh
Algorithms

Rod cutting problem

In this article, we explored the rod cutting problem in depth which can be solved using a Dynamic Programming approach that takes O(N^2) time and O(N) space

K. Sai Drishya K. Sai Drishya
Algorithms

Find the number of subsets of an array having a given XOR value

We are given an array of size N and a value M, we have to find the number of subsets in the array having M as the xor value of all elements in the subset. This can be solved using Dynamic Programming in linear time.

Siddharth Agarwal Siddharth Agarwal
Algorithms

Longest repeating and non overlapping substring in a string

We have to find the longest repeating and non-overlapping substring in a given string. Brute force approach takes O(N^3) time while Dynamic Programming takes O(N^2) time.

Ashutosh Singh Ashutosh Singh
Algorithms

Shortest Path with k edges using Dynamic Programming

Given a weighted directed graph, we need to find the shortest path from source u to the destination v having exactly k edges. Brute force approach takes O(V^k) time complexity which we reduce to O(V^3 * k) using dynamic programming

Sadanand Vishwas Sadanand Vishwas
Algorithms

Number of paths with k edges using Dynamic programming and Divide and Conquer

Given a directed graph, we need to find the number of paths with exactly k edges from source u to the destination v. A brute force approach has time complexity which we improve to O(V^3 * k) using dynamic programming which we improved further to O(V^3 * log k) using a divide and conquer technique.

Sadanand Vishwas Sadanand Vishwas
Algorithms

Number of ways to pair elements

In this article, we are going to discuss about element pairing problem where we need to find the number of ways a set of elements can be pair or kept separate. This can be solved using Dynamic Programming in linear time O(N).

Sourajeet Mohanty Sourajeet Mohanty
Algorithms

Break a number in 3 parts (n/2, n/3, n/4) recursively to get maximum sum

Given a number n, we can divide it in only three parts n/2, n/3 and n/4 recursively and find the maximum sum of the 3 parts. This can be solved in linear time using Dynamic Programming

Shubham Kumar Shubham Kumar
Algorithms

Largest subset with divisible pairs

We explored the method to get the longest subset within any given array, such that for each pair, the smaller number divides the larger number using Dynamic Programming.

Ishmeet Singh Kalra Ishmeet Singh Kalra
Algorithms

Calculate Binomial Coefficient using Dynamic Programming

Using a recursive relation, we will calculate the N binomial coefficient in linear time O(N * K) using Dynamic Programming

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Maximum Sum Rectangle in a Matrix

Given a 2D array, we need to find the subarray with the maximum sum of its elements. We solve this using Dynamic Programming in O(N^3) where brute force takes O(N^5)

Mansi Kathuria
Algorithms

Calculate Newman Conway Sequence

Newman Conway Sequence is the sequence which follows a given recursive relation (p(n) = p(p(n-1)) + p(n-p(n-1))). We solve it using Dynamic Programming in O(N) time

Piyush Rajendra Chaudhari Piyush Rajendra Chaudhari
Algorithms

Find number of subsets with sum divisible by given number M

Find the number of subsets with sum divisible by given number M. We solved this using a Dynamic Programming approach with time complexity O(N * M).

Siddharth Agarwal Siddharth Agarwal
Algorithms

Finding the number of sub matrices having sum divisible by K

This article is about counting the number of sub-matrices such that the sum of the elements is divisible by k and using Dynamic Programming, we solve it in O(N^3)

Shalini Jaiswal
Algorithms

Number of ordered pairs such that (A[i] & A[j])=0

Given array A[] of n integers, find out the number of ordered pairs such that (A[i]&A[j])=0. This can be done using dynamic programming in O(N*(2^N)) time

Shruti
Algorithms

Largest rectangular sub matrix having sum divisible by k

This article is about finding the size of the largest area of the rectangular sub-matrix such that the sum of the elements is divisible by k.

Shalini Jaiswal
Algorithms

Calculating Permutation Coefficient

Given n and k, we will calculate permutation coefficient using dynamic programming in O(N * K) time complexity.

Shruti
OpenGenus IQ © 2025 All rights reserved â„¢
Contact - Email: team@opengenus.org
Primary Address: JR Shinjuku Miraina Tower, Tokyo, Shinjuku 160-0022, JP
Office #2: Commercial Complex D4, Delhi, Delhi 110017, IN
Top Posts LinkedIn Twitter
Android App
Apply for Internship