-1

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

Lukar
  • 1
  • 3
  • 2
    Does this answer your question? [Understanding how recursive functions work](https://stackoverflow.com/questions/25676961/understanding-how-recursive-functions-work) – Ignatius Reilly Oct 26 '22 at 00:39

1 Answers1

0

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.

Woody1193
  • 7,252
  • 5
  • 40
  • 90
  • Thank you for the response, it is explained really well! I would love to upvote but stackoverflow wont let me because my reputation is too low or something. Thank you! – Lukar Oct 26 '22 at 03:29
  • 1
    @Lukar No problem. If this answer helped you you can click on the check mark next to it to mark it as the official answer. – Woody1193 Oct 26 '22 at 04:14