For the recursive factorial function output shown below, which lines of output would reflect the backward phase?

1 factorial(3)
2 3 * factorial(2)
3 3 * 2 * factorial(1)
4 3 * 2 * 1
5 3 * 2
6 6

(1 point)
Responses

4,5,6
4,5,6

1,2,3
1,2,3

1,2,3,4,5,6
1,2,3,4,5,6

1,4

1 answer

In a recursive factorial function, the forward phase is when the function calls itself and works towards the base case, while the backward phase is when the function resolves the calls and calculates the final result.

In the given output:

  • Line 1 (factorial(3)) starts the call.
  • Line 2 (3 * factorial(2)) continues the forward phase.
  • Line 3 (3 * 2 * factorial(1)) continues the forward phase.
  • Line 4 (3 * 2 * 1) is the base case, where the recursion starts resolving.
  • Line 5 (3 * 2) is part of resolving the recursive calls.
  • Line 6 (6) shows the final computed result.

Thus, the lines of output that reflect the backward phase are Lines 4, 5, and 6.

The correct answer is: 4, 5, 6.