Can someone explain what exactly a recursion is but in a way that anyone can understand?
I'm trying to find out what a recursion is
Recursion is the process of solving a problem by applying the same procedure to progressively smaller subsets of the original problem until a trivial case is reached. The basic example for this is finding the nth Fibonacci number:
func Fibonacci(n int)
if n = 0
return 0
elif n < 3
return 1
else
return Fibonacci(n - 1) + Fibonacci(n - 2)
This function works by calling itself for values of n that are equal to or greater than 3. This is called the recursive case. The other two situations (n = 0 or 3 > n > 0) are called base cases and provide a stop condition for the recursion.
All recursive functions can be written using a looping structure, but this is usually a fairly complicated process.
I'd say this provides a decent layman's explanation as well.