Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

boolean toSearch( int[] numbers, int vals, int down, int up ){ int middle = (beg

ID: 3752902 • Letter: B

Question

boolean toSearch( int[] numbers, int vals, int down, int up ){

int middle = (begin + end) >> 1;

if( down > up )

return false;

if( vals == numbers[middle] )

return true;

else if( vals > numbers[middle] )

return toSearch(numbers, vals, middle + 1, up);

return toSearch(numbers, vals, down, middle - 1);

}

What is the best case complexity when searching for a single vals item in numbers?

What is the worst case complexity when searching for a single vals item in numbers?

What is the worst case complexity when searching for n^2 vals items in numbers?

Explanation / Answer

Answer:

1) for single value item in numbers the best case complexity will be O(1). That means the result will be come after running the function in one time. whether the value is present or not.

2.) Simillarly, in worst case scenario, the complexity also will be O(1) times.

3) In this scenario the searching level will be worst case and in worst case scenario for n square value it will be O(log n) times.