+ 9

Why Recursion is tough but Beautiful as well ?

I would like to make all programs in recursion but it takes lot of time.

31st Jul 2019, 6:29 AM
dcodr
dcodr - avatar
11 Réponses
+ 22
Building a recursive structure requires a different thought process compared to building iterative ones. It's not tough, just different and hence requires some time to get used to. I wouldn't advice making all programs work recursively though. Why hurt yourself.
31st Jul 2019, 6:36 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Think fractals - recursive patterns in Nature like snowflakes 🧐 They are essentially recursive patterns !🌻
31st Jul 2019, 3:03 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 5
If you want an example of recursion , here is one: https://code.sololearn.com/cOghumul288E/?ref=app
31st Jul 2019, 6:19 PM
Qasem
+ 4
It's beautiful because it can make the code look/feel neat. It's tough maybe for a beginner if they don't handle the base case well and they run into infinite recursion.
1st Aug 2019, 6:50 AM
Sonic
Sonic - avatar
+ 2
Infinite recursion = stack overflow 🦀
1st Aug 2019, 1:28 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
IMHO the classic example of recursion is Fibonacci series 🤔
1st Aug 2019, 11:08 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
I think recursion looks good but show worst perfomance sometimes.First of all in some calculations u can use cycle with data inside and one instance of function. Its almost always less data in memory when u use many instance of function with same data. And second u spend processor time to read and write all of this excessivly data. But i use it:) because sometimes understand algorithm really easy in recursive.
1st Aug 2019, 11:30 AM
Chicherin Alexey
Chicherin Alexey - avatar
+ 1
Some problem is recursive, some other iterative, in its nature. Someone else is functional... Happy coding, whatever your style!
31st Jul 2019, 6:11 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
+ 1
Ifyou need help then stackowerwolf website 👍🏻👍🏻👍🏻
31st Jul 2019, 11:08 PM
İbrahim Berk AKGÜN
İbrahim Berk AKGÜN - avatar
0
Sometimes recursion is the way to go, but other times iteration is better. In general, recursion is slow because function calls are slow and recursion also risks infinite loops and stack overflow. However, some things like fractals and the Towers of Hanoi work well with recursion; it just depends on the program structure you need to solve a particular problem.
2nd Aug 2019, 4:34 AM
Kayla O'Donnell
Kayla O'Donnell - avatar
- 1
😑
1st Aug 2019, 4:46 PM
☆Erfan♡