Question: iven these two methods: METHOD math 1 : public int math 1 ( int n ) { if ( n < = 1 ) {

iven these two methods:
METHOD math1:
public int math1( int n ){
if (n <=1){
CS557D: Algorithms (Instructor: Dr. Riabov) Final Exam Fall 2024
____________________________________________________________________________________
2
return 1;
}// if
else {
return ( n *2)+ math1( n-1);
}// else
}// math1
METHOD math2:
public int math2( int n ){
if (n <=1){
return 1;
}// if
else {
return n + math1( n )* math2( n/2);
}// else
}// math2
(a) Set up a recurrence relation for the running time of the method math1 as a function of n.
Solve your recurrence relation to specify THETA bound of math1.
(b) Now set up a recurrence relation for the running time of the method math2 as a function
of n. Solve your recurrence relation to specify the Big-O bound of math2.
HINT: When doing this, the call to math1 can be replaced by the equation that you found
when solving the recurrence relation for math1 in part (a))

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 Programming Questions!