You are on page 1of 1

UNIVERSITI UTARA MALAYSIA

UUM COLLEGE OF ARTS AND SCIENCES


STIA2024 DATA STRUCTURES AND ALGORITHM ANALYSIS
EXERCISE: RECURSION

1. Study the method func3() below, then trace the execution of the method call
func3(6,4) and func3(-5,1) by drawing stack of activation record and a recursive tree
for each call. What are the values that will be returned by these calls?

private int func3(int m, int n) {


if (m < n)
return 0;
else
return 1 + func3(m-n, n);
}

a) func3(6, 3)

b) func3(-5, 1)

2. Write a recursive method for the following function.


f(n) = 3 + 5 + … + (2n + 3), where n >=0

You might also like