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

Use the RecBinarySearch function (below) to complete the Binary Search HW (below

ID: 3904809 • Letter: U

Question

Use the RecBinarySearch function (below) to complete the Binary Search HW (below):

template <class T>

int RecBinarySearch(const T[ ] A, T target, int bottom, int top)

{

int middle;

if (bottom < top) {

        middle = (top + bottom) / 2;

        if (target == A[middle] )

return middle;

        if (target < A[middle] )

return RecBinarySearch(A,target,bottom,middle-1);

        else

              return RecBinarySearch(A,target,middle+1,top);

} else if (bottom == top) {

        if (target == A[top])

               return top;

}

    return -1; // target not found

}

Binary Search Homework Fill in the values of low, high and mid for each recursive call when binary search for value 6 is called for the array below; then show the index that is returned. 0 1 2 3 45 6 7 8 9 10 11 12 13 14 15 16 2 4 6810 1214 16 1820 22242628 30 32 34 low high mid Value returned:

Explanation / Answer

If you have any doubts, please give me comment...

Value returned: 2

low high mid 0 16 8 0 7 3 0 2 1