Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 23, 2021 03:12 pm GMT

Recursion explained

In this article we will break down all the concept you need to know before saying that you fully understand recursion. The goal is to talk about those concepts so that you can come up with your own definition of what recursion is .

Definition : Recursion is mostly described as a process that calls it self.
It can also be described by a function that calls it self.

Call Stack : In case we're calling a function or more multiple times in a program,
their is a thing called "Call Stack" that is an actual stack in witch functions are placed
on top of each other in terms of execution,
so the call stack can hold informations about all the functions that are placed on it.

So when using a recursive function what happen is we keep pushing the same function onto the "Call Stack".

What's the main structure of a recursive function ? :

A recursive function has two essential parts wich are the base case and a different input (or function argument).

1) The base case :
For the base case you can, think of it as a condition that causes the function to stop calling it self, in other words it stops the recursion.

2) Different input : Everytime a recursive function is being called, we need to make sure that the input aren't the same.

If one of the two or both are missing the process can resolve in what called a
"Stack overflow" forcing you to spend hours looking for answers on stackoverflow.com .


Original Link: https://dev.to/jrmatanda/recursion-explained-1d45

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To