Recursion vs DP

What is better filling table with recursion or by looping !

This discussion on stackoverflow will help you a lot.


Recursion is a programming technique that allows the programmer to express operations in terms of themselves. In C, this takes the form of a function that calls itself. A useful way to think of recursive functions is to imagine them as a process being performed where one of the instructions is to “repeat the process”. This makes it sound very similar to a loop because it repeats the same code, and in some ways it is similar to looping. On the other hand, recursion makes it easier to express ideas in which the result of the recursive call is necessary to complete the task. Of course, it must be possible for the “process” to sometimes be completed without the recursive call. One simple example is the idea of building a wall that is ten feet high; if I want to build a ten foot high wall, then I will first build a 9 foot high wall, and then add an extra foot of bricks. Conceptually, this is like saying the “build wall” function takes a height and if that height is greater than one, first calls itself to build a lower wall, and then adds one a foot of bricks.

In recursion, because its a function call, calling overhead i.e. storing values on stacks and then returning back is quite expensive in terms of memory and time.So we should use loops.

If memory is important than to time then use Loop otherwise you should use the recursion. Because recursion takes more memory than to loop but If same function are used many times then you try to use recursion…