+ 5
Is using recursion in python better than using for loop and while loop for getting the desired result?
Is it necessary to use recursion, does it make you look like a professional programmer ? Because I sometimes get stuck at recursion. Is there any way I can make my recursion technics strong?
3 Respostas
+ 2
It depends. Sometimes recursion can save you a lot of lines and the code looks clean. But sometimes it's not efficient (because it uses stack for computation and results in a higher space complexity) and it's better to use a loop instead.
But, recursion is something you just can't ignore. It is very useful when dealing with data structures such as trees and graphs.
I recommend you watch this video by the author of a book called "Think like a programmer". I am pretty sure it will take your fear of recursion away.
https://youtu.be/oKndim5-G94
+ 1
I think you will enjoy this blog..
https://hackernoon.com/recursion-vs-looping-in-JUMP_LINK__&&__python__&&__JUMP_LINK-9261442f70a5
- 2
Avoid both if you can.