int func1 (int m, int n) { if (m==n || n==1) return 1; else return func1(m-1,n-1
ID: 3615746 • Letter: I
Question
int func1 (int m, int n) {if (m==n || n==1)
return 1;
else
return func1(m-1,n-1) + n*func1(m-1,n);
}
Based on the function above;
a) What precondition must exist in order to prevent the code abovefrom infinite recursion?
a. m >= 0 and n >=0 b. m >= 0 andn>= 1
c. m >= 1 and n >=0 d. m >= 1 andn >= 1
b) Which of the following function calls would result in the value1 being returned?
a. func1(0,1) b. func1(1,0)
c. func1(2,0) d. func1(1,2)
c) Which of the following would be an invalid call to the functionabove?
a. func1(0,1) b. func1(1,0)
c. func1(4,9) d. func1(99999,99999)
feel free to answer in multiple posts
Explanation / Answer
a. I would say that both m and n have to be greater than 0because when the first condition is not met and it goes to the elsestatement then it will just keep going infinitely. An example wouldbe let's say if we called func1(-1,-1) we would get = func1(-2,-2) + -1*func1(-2,-1) = 1 + -1*func1(-2,-1). Thefirst function would return 1 but the second function would keepgoing infinitely. func1(0,1) would return 1 because in this case n == 1 and thefirst condition is met the function returns 1 and won't go to therecursive calls.Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.