+ 4
where can I apply recursion code in real programming
4 Respostas
+ 6
Recursion is less memory efficient, in most cases, creating a large stack of function calls in place of looping code. But its more code efficient, replacing many more lines of looping code with a handful of recursive code. In some cases the recursion is also more intuitive. Consider this pseudocode for traversing a tree:
def traverse (root):
if root.left :
traverse (root.left);
print(root);
if root.right :
traverse (root.right);
+ 3
there are lots of uses for recursion, as it is essentially another type of loop. As for specifically where to use it, that is entirely up to you and whatever your program requires.
+ 1
@Kimberly I love that example!
+ 1
thanks all