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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started