English

Determine the number of comparisons required in list [-4, 0, 2,7, 8, 17, 19] to search for - 4. -

Advertisements
Advertisements

Question

Determine the number of comparisons required in list [-4, 0, 2,7, 8, 17, 19] to search for - 4.

Options

  • 1

  • 2

  • 3

  • 4

MCQ

Solution

1

Explanation:

Give list = [-4, 0, 2,7, 8, 17, 19]

Iteration 1: First = 0, last = 6

Midpoint= (0+6)//2 = 6112 = 3, value at index 3 is 7.

-4 < 7, so we will consider first half of the list

Iteration 2: First = 0, last = 2

Midpoint= (0+2)//2 = 1, value at index 1 is 0

-4 < 0, so we will consider left half

Iteration 3: First = 0, last = 0

Midpoint = 0//2 = 0

Number at index 0 is -4

shaalaa.com
Binary Search
  Is there an error in this question or solution?
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×