Here is an array with exactly 15 elements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Suppose that we are doing a binary search for an element. Circle any elements that will be found by examining two or fewer numbers from the array.
//////////////////////////////////////////////////////////////////////////////
This is a practice problem from my textbook for my C++ course. I am a little confused because looking up answers online and comparing with my own, they are not matching up. Online people are saying the answer is 8, 4, and 12 while I think it is 7, 11, and 3.
1 Answer 1
The middle element of the array is 8, not 7. Then you are left with two subarrays the first of which has 4 as the mid element and the other 12... Not sure how this could be further explained. There are as many elements to the left of 8 as there are to the right...
arr[7](remember, indexing starts at 0, soarr[0] == 1, etc.) ?