- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 201 Articles for Dynamic Programming
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
237 Views
When a binary matrix is given, our task is to find a square matrix whose all elements are 1.For this problem, we will make an auxiliary size matrix, whose order is the same as the given matrix. This size matrix will help to represent, in each entry Size[i, j], is the size of a square matrix with all 1s. From that size matrix, we will get the maximum number to get the size of the biggest square matrix.Input and OutputInput: The binary matrix. 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 1 1 ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
465 Views
There is a chain of pairs is given. In each pair, there are two integers and the first integer is always smaller, and the second one is greater, the same rule can also be applied for the chain construction. A pair (x, y) can be added after a pair (p, q), only if q < x.To solve this problem, at first, we have to sort given pairs in increasing order of the first element. After that, we will compare the second element of a pair, with the first element of the next pair.Input and OutputInput: A chain of number pairs. ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
823 Views
Longest Palindromic Subsequence is the subsequence of a given sequence, and the subsequence is a palindrome.In this problem, one sequence of characters is given, we have to find the longest length of a palindromic subsequence.To solve this problem, we can use the recursive formula, If L (0, n-1) is used to store a length of longest palindromic subsequence, thenL (0, n-1) := L (1, n-2) + 2 (When 0'th and (n-1)'th characters are same).Input and OutputInput: A string with different letters or symbols. Say the input is “ABCDEEAB” Output: The longest length of the largest palindromic subsequence. Here it is ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
Longest Increasing Subsequence is a subsequence where one item is greater than its previous item. Here we will try to find Longest Increasing Subsequence length, from a set of integers.Input and OutputInput: A set of integers. {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15} Output: The length of longest increasing subsequence. Here it is 6. The subsequence is 0, 2, 6, 9, 13, 15.AlgorithmlongestSubSeq(subarray, n)Input − The sub array and the size of sub array.Output − Longest increasing sub sequence length.Begin define array length of size n initially set 0 ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
292 Views
A matrix of different characters is given. Starting from one character we have to find the longest path by traversing all characters which are greater than the current character. The characters are consecutive to each other.To find the longest path, we will use the Depth First Search algorithm. During DFS, some subproblems may arise multiple times. To avoid the computation of that, again and again, we will use a dynamic programming approach.Input and OutputInput: The matrix as shown above. And the starting point. Here the starting point is e. Output: Enter Starting Point (a-i): e Maximum consecutive path: 5AlgorithmfindLongestLen(i, j, ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
255 Views
A sequence is said to be bitonic if it is first increasing and then decreasing. In this problem, an array of all positive integers is given. We have to find a subsequence which is increasing first and then decreasing.To solve this problem, we will define two subsequences, they are the Longest Increasing Subsequence and the Longest Decreasing Subsequence. The LIS array will hold the length of increasing subsequence ending with array[i]. The LDS array will store the length of decreasing subsequence starting from array[i]. Using these two arrays, we can get the length of longest bitonic subsequence.Input and OutputInput: A ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
651 Views
An array of integers is given. We have to find the sum of all elements which are contiguous, whose sum is largest, that will be sent as output.Using dynamic programming we will store the maximum sum up to current term. It will help to find the sum for contiguous elements in the array.Input and OutputInput: An array of integers. {-2, -3, 4, -1, -2, 1, 5, -3} Output: Maximum Sum of the Subarray is: 7AlgorithmmaxSum(array, n)Input − The main array, the size of the array.Output − maximum sum.Begin tempMax := array[0] currentMax = tempMax for i := ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
295 Views
The Independent Set is the subset of all binary tree nodes when there is no edge between any two nodes in that subset. Now from a set of elements, we will find the longest independent set. i.e. If the elements are used to form a binary tree, then all largest subset, where no elements in that subset are connected to each other.Input and OutputInput: A binary tree. Output: Size of the Largest Independent Set is: 5AlgorithmlongSetSize(root)In this algorithm Binary tree will be formed, each node of that tree will hold data and setSize.Input − Root node of the binary tree.Output − ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
179 Views
Let us consider, we will try to write the letter ‘A’, using the keyboard. Our goal is to use only four keys and try to write maximum ‘A’s on the text field. The keys are ‘A’, ‘C’, ‘V’ and ‘Ctrl’.To write the maximum number of A, we will use Ctrl + A to select All, Ctrl + C to copy and Ctrl + V to paste.Input and OutputInput: Number of keystrokes, say 7 Output: Maximum Number of A's with 7 keystrokes is: 9 Press A three times. Then Ctrl+A, Ctrl+C, Ctrl+V, Ctrl+VAlgorithmkeyNumbers(keyStrokes)Input: number of keystrokes.Output: Maximum number of letters using these ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
The Fibonacci sequence is like this, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ……In this sequence, the nth term is the sum of (n-1)'th and (n-2)'th terms.To generate we can use the recursive approach, but in dynamic programming, the procedure is simpler. It can store all Fibonacci numbers in a table, by using that table it can easily generate the next terms in this sequence.Input and OutputInput: Take the term number as an input. Say it is 10 Output: Enter number of terms: 10 10th fibinacci Terms: 55AlgorithmgenFiboSeries(n)Input: max number of terms.Output − The nth Fibonacci ... Read More