menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Dynamic Pr...
source image

Prodevelopertutorial

1M

read

393

img
dot

Image Credit: Prodevelopertutorial

Dynamic Programming: Longest Increasing Subsequence

  • Dynamic Programming approach to solve the problem of finding Longest Increasing Subsequence in an Array of integers.
  • We start with a DP array to store the longest increasing subsequence till that index, initially filled with 1 at every index.
  • We take two variables i and j where i starts from index [1] and j starts from 0 to i.
  • We check if the value at array[j] is less than the value at array[i], then we perform an operation in our DP table, then we increment the index of 'j'.
  • When 'j' and 'i' reaches to the same index, we increment the 'i' value to point to next element and reset the 'j' value to 0.
  • DP array will always show the Longest Increasing Subsequence till that index.
  • The above process is repeated until we reach the end of the array and the maximum value of DP array gives our required result.
  • This algorithm provides the longest increasing subsequence in O(n^2) time complexity.
  • This problem has a Dynamic Programming solution with a relatively simple recursive formulation.
  • This technique of solving sub-problems and building up solutions to larger problems is the key idea of Dynamic Programming.

Read Full Article

like

23 Likes

For uninterrupted reading, download the app