I have come across while developing my program in Java. I need to figure out how efficient this method is in Big-O notation.
This is what my boss told me:
Making use of a suitable Big-O expression, state and explain in some detail the time complexity of method compute. Your explanation must include a justification for the chosen Big-O expression and make reference to the number of calls to compute at Line 6.
public int compute(int[] array, int first, int last) {
int result = 0;
if(first < last) {
result = array[first] + compute(array, first+2, last);
}
else if(first < array.length) {
result = array[first];
}
return result;
}