In a recursive factorial function, the backward phase occurs after all the recursive calls have been made and is where the results of those calls are combined to produce the final output.
Looking at the lines:
factorial(3)
- Initiating the call.3 * factorial(2)
- During the first level of recursion.3 * 2 * factorial(1)
- Continuing recursion.3 * 2 * 1
- The base casefactorial(1)
has been resolved.3 * 2
- The result offactorial(2)
is combined with3
.6
- The final result offactorial(3)
.
The backward phase starts when the base case is reached (line 4) and continues until the final result is computed (line 6). Therefore, the lines that reflect the backward phase are:
4, 5, 6
So, the correct response is:
4,5,6