How to know which type of DP can be applied?

I’m new to dynamic programming. In many cases, I’ve seen that, a recursive solution is applied. For eg.:

solve(){

dp[i][j] = solve() * some_condition;

}

But, in some cases, we simply apply a 2D loop over all the DP matrix.

I’m not able to understand, when we apply a recursive solution, and when we apply a 2D loop.

I think I am missing something in the concept.

Please help.

@siddharth_1_3277,
Calling a recursive function usually means top-down dp, which means that we try to come from larger sub-problems to smaller ones(recursively).
And iterative is bottom-up dp, which means we first solve smaller sub-problems, starting from base case, and then solving larger subproblems.
If you notice carefully, what both the methods do is basically the same thing, filling up the dp table.
It’s okay to be confused when you are new to it, you will get a hang of it, dp is more of an intuitive thing than theoretical, I think.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Yeah, I got it…Thanks