Recursion

A recursive function is one that calls itself in the method body.

A recursive function breaks down a problem into smaller iterative pieces. The function keeps iterating and calling itself until it reaches the "base case", or the simplest case. At this point, the function "winds back" to the first call.

A helpful method for tracing a recursive function is to write down each method call in a "staircase" formation. Once you reach the base case, start moving back up the staircase, figuring out what each method call returns until you get to the first method call.

No comments:

Post a Comment