-3

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.

asked Apr 3, 2015 at 22:05
2
  • Remember: No zero element Commented Apr 3, 2015 at 22:09
  • There are 15 elements. 15/2 = 7, what element is in arr[7] (remember, indexing starts at 0, so arr[0] == 1, etc.) ? Commented Apr 3, 2015 at 22:10

1 Answer 1

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...

answered Apr 3, 2015 at 22:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.