A recurrence relationship is an imperative part of a dynamic programming approach.
I was solving the problem of finding the minimum number of edits needed to create a palindromic string.
dp[i, j] = min(
dp[i+1, j-1] if s[i] == s[j],
dp[i+1, j-1] +1,
dp[i+1, j] +1
dp[i, j-1] +1
)
After formulating the recursive equation, it's trivial to implement a top down approach that uses a hash table.
What I can't understand is how to use this recursive formula to build the solution table from the bottom up. By doing it bottom up, we save memory as we don't need to compute a recursion stack. It's also a bit more elegant to do it bottom up.
So, to flip this recurrence and start from the bottom up. We need to consider substrings that have a length of 1 to length of N. However, I'm struggling with creating these for loops appropriately.
My question: Once formulating the top-down recurrence for a DP problem, how do we flip it and use a bottom up approach to fill in the subsolution table?