What is recursion?
The C programming function above calculates the result of exponentiation when given a base and exponent. In the function, x is the base and y is the exponent. The function cleverly calls itself repetitively. In computer programming, this type of function is called recursion. One of the most important components of a recursive function is the base case. Without it, the function will never end because it wouldn't know when to stop. Another important component is the stack in which the function operates on. The stack is a data structure that pushes every call of the function onto it and then, pops them out to return the final value. It follows a LIFO (Last In First Out) order.
In the chart below, x is assigned 3 and y is assigned 3. Since the exponent is a positive number, the function will multiply the base three times. Once the last call is the base case, the stack will pop the return values off until the result of 27 is returned.
In the chart below, x is assigned 3 and y is assigned -3. Since the exponent is a negative number, the function will divide the base three times. Once the last call is the base case, the stack will pop the return values off until the result of 0.037037 is returned.
Resources
0. https://www.mathsisfun.com/exponent.html
1. https://www.geeksforgeeks.org/recursion
2. https://www.thecodingdelight.com/understanding-recursion-javascript