J
Johnathan Dole
Hello All, I'm having a little difficulties understanding Recurrence
Relation. We where given a number of Java recursive methods and where asked
to give a recurrence relation that expresses the number of multiplications
performed by the algorithm, and use the recurrence relation to derive a
worst-case time complexity for the algorithm.
public static int power2(int base, int exponent) {
if (exponent == 0)
return 1;
if (exponent == 1)
return base;
int part = power2(base, exponent/2);
if (exponent % 2 == 0)
return part * part;
return base * part * part;
}
Would be grealty appriciated if someone could help me solve the followinf
method, so i can try to do the others myself.
Thanks
John
Relation. We where given a number of Java recursive methods and where asked
to give a recurrence relation that expresses the number of multiplications
performed by the algorithm, and use the recurrence relation to derive a
worst-case time complexity for the algorithm.
public static int power2(int base, int exponent) {
if (exponent == 0)
return 1;
if (exponent == 1)
return base;
int part = power2(base, exponent/2);
if (exponent % 2 == 0)
return part * part;
return base * part * part;
}
Would be grealty appriciated if someone could help me solve the followinf
method, so i can try to do the others myself.
Thanks
John