Question: 2. Given a search function in Program 2. Answer all the following questions based on INPUT array shown in Figure B2. 1/Program 2 int search

2. Given a search function in Program 2. Answer all the following questions based on INPUT array shown in Figure B2. 1/Program 2 int search ( int search key, int array size, const int INPUT() ) { bool found = false; int index = -1 //-1 means record not found int MIDDLE, LEFT = 0, RIGHT = arraysize-1; while ((LEFT search key) RIGHT = MIDDLE - 1; // search is focused on the left // side of list else LEFT = MIDDLE + 1; // search is focused on the right // side of the list } //end while return index; }//end function 0] 5 [1] 9 [2] 19 [3] 25 [4] 34 [5] 40 [6] 45 [7] 49 [8] 66 [9] 75 [10] 88 [11] 100 Trace the value of LEFT, RIGHT, MIDDLE, INPUT(MIDDLE) and found (as in Table B1) for binary search operation performed onto INPUT array with the key numbers being search as following: 1. Search Key=40 2. Search Key=100 3. Search Key=8 Table B1 LEFT RIGHT MIDDLE INPUT(MIDDLE) found
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
