How to solve longest Palindromic Subsequence using dynamic programming step by step

preview_player
Показать описание
In the previous video of Joey'sTech, we worked together on developing the intuition to solve the longest palindromic subsequence problem using dynamic programming
technique.

We came up with a list of thoughts which are closer to designing the algorithm of maximum palindromic subsequence which is one of the most interesting dynamic programming problems.

In this video of dynamic programming tutorial,using that list we will now solve longest palindromic subsequence step by step by filling the 2D matrix in the order of increasing lengths.

If you have not seen the intuition video then I highly recommend to watch it because that will really help you develop your skills and is the right answer to how to solve dynamic programming problems.
This is indeed the right way to learn dynamic programming.

A palindrome is a string which is the same when read from the left as well as when read from the right. Examples include rotor, racecar,madam etc.
So, while solving it you need to see if you're checking the palindrome while solving every sub problem.

We will begin with length 1 which depicts that the lowest sub problem is going to be the individual letters of the string. The entire solution lies how are you going to put the base state.
Since, at length 1 we are getting the lowest possible longest palindromic subsequence hence, in our 2d matrix we'll put 1 (for match) diagonally which will depict the values for (c,c)(b,b)(e,e) and so on.

Once, you have put the base case there in your 2D matrix then you just have to increment the length by 1 and look at the cases then.
If you follow this approach or similar approach then solving longest palindromic subsequence problem or any other dynamic programming problem will become a piece of cake for you.

Now, let's solve together the LPS problem using DP step by step in this video of Joey'sTech.
Рекомендации по теме
Комментарии
Автор

Your explanation is good...but it would be better to explain the complete code as well...

abhiyb