1 / 11
Settings
<<<>>>
Suppose that we want to compute the value of factorial(5) using the following recursive factorial implementation.
- int factorial(int n) {
- if (n <= 1)
- return 1;
- return n * factorial(n-1);
- }
- int factorial(n = 5) {
- if (5 <= 1)
- return 1;
- return 5 * factorial(4);
- }
- int factorial(n = 4) {
- if (4 <= 1)
- return 1;
- return 4 * factorial(3);
- }
- int factorial(n = 3) {
- if (3 <= 1)
- return 1;
- return 3 * factorial(2);
- }
- int factorial(n = 2) {
- if (2 <= 1)
- return 1;
- return 2 * factorial(1);
- }
- int factorial(n = 1) {
- if (n <= 1)
- return 1;
- }
- int factorial(n = 2) {
- if (2 <= 1)
- return 1;
- return 2 * 1;
- }
- int factorial(n = 3) {
- if (3 <= 1)
- return 1;
- return 3 * 2;
- }
- int factorial(n = 4) {
- if (n <= 1)
- return 1;
- return 4 * 6;
- }
- int factorial(n = 5) {
- if (5 <= 1)
- return 1;
- return 5 * 24;
- }