Question 120Asked in CIL MT Systems, 26 Mar 2017 (12:30 PM)

Consider the list of numbers 1, 2, 3, …, 1000 is stored in a[0..999]. What will be the total number of comparisons to search x = 501 using the following…

Consider the list of numbers 1, 2, 3, …, 1000 is stored in a[0..999]. What will be the total number of comparisons to search x = 501 using the following binary search() function? int binary_search(int a[], int n, int x){ int low=0, high=n-1; while(low <= high){ int m = (low + high) / 2; if(x > a[m]) low = m + 1; else if(x < a[m]) high = m − 1; else return m; } return -1; }
  1. A2
  2. B15
  3. C17
  4. D1
Show answerHide answer

Correct answer: (C) 17

From CIL MT Systems PYQ, 26 Mar 2017 (12:30 PM)

This is question 120 of CIL MT Systems PYQ, 26 Mar 2017 (12:30 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.