R13.2 Outline, but do not implement, a recursive solution for finding the smalle
ID: 3732198 • Letter: R
Question
R13.2 Outline, but do not implement, a recursive solution for finding the smallest value in an array.
R13.4 Outline, but do not implement, a recursive solution for sorting an array of numbers. Hint: First find the smallest value in the array.
R13.6 Write a recursive definition of xn, where n 0.
Hint: How do you compute xn from xn – 1? How does the recursion terminate?
R13.8 Write a recursive definition of n! = 1 × 2 × . . . × n.
Hint: How do you compute n! from (n-1)!? How does the recursion terminate?
Explanation / Answer
R13.2 Outline, but do not implement, a recursive solution for finding the smallest value in an array.
f1(arr,start,end) = {
arr[start], when start == end;
min(arr[start],f1(arr,start+1,size)), when start < end
}
R13.4 Outline, but do not implement, a recursive solution for sorting an array of numbers. Hint: First find the smallest value in the array.
f2(arr,start,end) = {
Nothing, when start == end
arr[start] = min(arr[start],f2(arr,start+1,size)), when start < end
}
R13.6 Write a recursive definition of xn, where n 0.
Hint: How do you compute xn from xn – 1? How does the recursion terminate?
x(n) = {
0, when x <= 0
n + x(n-1) when x>0
}
R13.8 Write a recursive definition of n! = 1 × 2 × . . . × n.
Hint: How do you compute n! from (n-1)!? How does the recursion terminate?
x(n) = {
0, when x <= 0
n * x(n-1) when x>0
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.