73.0k views
1 vote
Consider an array of integers consisting of the numbers: 8 12 19 32 45 55 67 72 89 90 92. Suppose the binary search algorithm is applied to this list to search for the key 56 ( not in the list). Answer the following questions: What is the index of the first element in the array that is compared with the key and how is this index evaluated

1 Answer

4 votes

Answer:

Answered below

Step-by-step explanation:

Index of the first element compared to the key is 5. The element itself is 55.

This index is evaluated by the addition of the index of the first element which is 0(zero) and the the index of the last element which is 10.

( Index of the last element is determined by subtracting the one from the total number of elements)

After the addition, the result is divided by 2 to get the first index from which the binary search begins.

firstIndex = 0

lastIndex = array.length - 1

midpoint = (firstIndex + lastIndex) / 2

User Jason Aden
by
6.0k points