This is an algorithm trace task. No implementation is required.
Read the following algorithm for the recursive function called Curiosity that needs two integers as inputs and returns an integer value.
In the algorithm, MOD is an operator. It works with two integers to give the remainder when the first integer is divided by the second. This means that
(a) Write down the output when the function is called with
(b) The function is called with
Write down in full each line that is executed, but replace each variable with its actual value and indicate on the IF statement line whether the result of the test is true or false. [7 Marks]
(c) Describe the purpose of the algorithm. [2 Marks]
(d) Rewrite the recursive function as an iterative algorithm. [6 Marks]