
When I was first reading up on recursive solutions to algorithms, I kept hearing about space complexity and the call stack, and at first had no ide...
For further actions, you may consider blocking this person and/or reporting abuse
I'm also from "The Odin Project" and feel like I lost a lot of wind in my sail after hitting recursion. Your analogy really helps with understanding the double edge nature of recursion. Thank you for the quick read!
From the Odin
Son of Odin here as well. Loved your article, especially the analogy provided at the end. Makes recursion really stick.
From TOP, I love how you simplified your article and not going all too technical on it.
Here's another way to make it more relatable
The Shopping Cart Analogy for Recursion
Imagine you’re at a mall, pushing a shopping cart. As you walk through the aisles, you pick up items one by one and place them in your cart. The first item you pick up goes at the bottom of the cart, the second item goes on top of it, and so on. You know the price of each item individually, but to find out the total cost, you need to go to the checkout counter.
Here’s where the magic of recursion comes in:
First In, Last Out (FILO):
At the checkout counter, the cashier starts by scanning the last item you added to the cart (the one on top). Then they move to the second-to-last item, and so on, until they finally reach the first item you placed in the cart (the one at the bottom).
Breaking It Down:
Each item is like a step in a recursive function. The cashier doesn’t calculate the total all at once—they process one item at a time, adding its price to the running total. This is similar to how a recursive function breaks a problem into smaller, manageable pieces.
The Base Case:
The checkout process ends when the cashier reaches the first item in the cart. In recursion, this is called the base case—the point where the function stops calling itself and starts returning results.
The Total:
Once all the items have been scanned, you get the total cost. In recursion, this is the final result after all the smaller problems have been solved.
Thanks for your analogy. And if you are from the Odin Project, this is my message to tell you that you're doing great and should not give up.
an Odinite too
Hello from TOP ^_^
Hola desde TOP. Excelente articulo, ,uy comprensible.
Hello from Odin also and thanks for the excellent explanation
From TOP - JS Course. Thanks for the clear and concise article.
Hello, I'm Odinite too!!
Hello from Odin project!
Any article used by Odin Project is doomed to be recognised only for being in Odin Project