Question: 1) Rewrite the recursive function fact (page 104 of the text) using tail recursion, and translate the tail recursive function as Legv8 assembly code. 2)

1) Rewrite the recursive function fact (page 104 of the text) using tail recursion, and translate the tail recursive function as Legv8 assembly code.

2) Rewrite the following recursive procedure as a tail recursive procedure:

int f ( int A[ ] , int low, int high) {

if (low == high)

return A[low];

else {

int temp = f(A, low+1, high);

if (temp < A[high])

return temp;

else

return A[high];

}

}

Hint: just as in the example we discussed in class, add an extra parameter temp that accumulates the result of recursive calls. In the latter case, you can use the min function of c (and c++) to accumulate.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!