Hello Engineers
Today, I will talk about recursion in what, why, and how.
What is recursion , why to use it, and how to solve problems w...
For further actions, you may consider blocking this person and/or reporting abuse
Nice post. Very interesting example with
hello world
being printed beforethe i value
. It almost looks like a recursive decorator. ;-)Recursion can be our best friend in many cases. But honestly, I am not sure that is best using recursion when iteration would work. I've run into some examples where recursion is needed and others where iteration is just best. What do you think?
I wrote once about Fibonacci with iteration and flat a list with recursion. Let me know your thoughts on it.
cheers
thank you .. I am glad you liked it 😊
and yes I agree with you 💯
looking at my example , the while function and the recursion function worked the same in result and time complexity .. but there is a difference that makes the while function better in this case which is the space complexity .
the while loop was updating the value of i which means the big O space complexity of the while function is O(1) "constant"
on the other hand, the recursion function was filling the stack every time with new function and different parameter , which means the big O space complexity is O(n)
so yes .. in many causes , using a normal iteration would be the best.
about your line in the article "I started this post to discuss that the Fib series might not be a good example to explain recursion." yes I totally agree and that's why I didn't use it
as you said there are better ways that will take less time and space
I liked your article I am gonna refer to it in my post
Thanks for the highlight 👏
and thanks for your comments. it is good to discuss. stay tuned. more is always coming 😉
I mean, that only applies to poorly designed languages, so it's not something to really worry about
EDIT: And poorly designed code, I should probably add
True 👍.. in many languages you can avoid this problem easily ..it seems like I will add writing a post about that to my future plans
That was informative and everything but I still hate recursive functions! Good job keep the good work
Thank you 🦁 .. I am trying to improve my content
Hey 👋, it's really a nice article. I have enjoyed a lot. Thank you for sharing 😊
There is typo about LIFO for stack principal. It has written Last In Last Out instead of Last In First Out.
OMG thanks for telling me 😂 😂 😂
That's what happens when you write an article at midnight 😁
Ha ha ha 😂. You are welcome.
explained very well! it is still a very alian topic for me though...
Please tell me what is the alien thing about it .. I'm willing to write another article if it will help
This dev-to-uploads.s3.amazonaws.com/up... was made by this JS-HTML recursion dapp: bestape.github.io/alchemy/
Are you the one who made it ?
that's so cool
You all might like this post too!
Good article 👍🏻
Keep it up
You can avoid the stack becoming full for long running recursive functions using trampolining. Maybe a good follow up post 👍
Totally right 👍🏻👍🏻👍🏻