I had done two other efficient recursive methods for LCS.
One using 2D int array as Recursive strorage
One using Hashmap in Recursive storage
Please tell me if they are valid ones.
I had done two other efficient recursive methods for LCS.
One using 2D int array as Recursive strorage
One using Hashmap in Recursive storage
Please tell me if they are valid ones.
Avoid using HashMap approach for memoization, especially for Strings as keys of HashMap. It is really space and time - consuming. Use bottom up DP wherever possible.
is 2D array method with recursion good?
Yeah. Thats the best.
How to find the approach for bottom up DP for a particular problem.
Okay so top-down DP may seem more intuitive initially, but the problem is as you do more complex problems, you’ll find that top-down carries a lot of overhead because of recursive function calls and debugging the code is also much difficult. So, always try to first think of the recursive pattern in the problem and then simply create an array of as many dimensions as the states in the DP(mostly not always). Then think of the base cases and fill the corresponding array elements and instead of recurring , use a loop to calculate the value for all the states. There is no preset way to convert any code to bottom-up DP but the more no of questions you do using this idea, the more clearer it will become to you.