April 2018
Beginner to intermediate
426 pages
10h 19m
English
Now, let’s try rewriting the factorialIterative function using recursion. But first, let’s define all the steps using a recursive definition.
The factorial of 5 is computed by 5 * 4 * 3 * 2 * 1. The factorial of 4 (n -1) is computed by 4 * 3 * 2 * 1. Computing (n - 1) is a subproblem we solve to compute n!, which is the original problem, so we can define the factorial of 5 as follows: