where can I apply recursion code in real programming | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

where can I apply recursion code in real programming

18th Sep 2016, 1:53 PM
Prince Kwekowe
Prince Kwekowe - avatar
4 Answers
+ 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);
27th Sep 2016, 12:13 PM
Kimberly Robasky
Kimberly Robasky - avatar
+ 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.
18th Sep 2016, 5:42 PM
Luke Armstrong
+ 1
@Kimberly I love that example!
27th Sep 2016, 12:50 PM
Luke Armstrong
+ 1
thanks all
31st Oct 2016, 5:13 PM
Prince Kwekowe
Prince Kwekowe - avatar