Top MCQs on Binary Search Algorithm with Answers (original) (raw)

What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?

Given an array arr = {12, 13, 35, 78, 56} and key = 78; How many iterations are done until the element is found using Binary search?

Select the best description to explain what a binary search algorithm is.

What is the best-case TIme complexity of Binary search to find an element?

A binary search is to be performed on the list:
3 5 7 10 23
How many comparisons would it take to find number 7?

What are the mid values (corresponding array items) produced in the first and second iterations for an array arr = [23, 45, 67, 89, 90,46 ]and key = 90?

Identify what the below function is doing.

C++ `

int fun(int arr[], int size, int key, int k) { int s = 0; int e = size - 1; int mid = s + (e - s) / 2; int ans = -1; while (s <= e) { if (arr[mid] == key) { if (arr[mid - k] == arr[mid]) e = mid - 1; else if (arr[mid - (k - 1)] == arr[mid]) { ans = mid; break; } else { s = mid + 1; } } else if (key < arr[mid]) { e = mid - 1; } else if (key > arr[mid]) { s = mid + 1; } mid = s + (e - s) / 2; } return ans; }

`

Which of the following is correct recurrence for worst case of Binary Search?

Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous.

C `

  1. f(int Y[10], int x) {
  2. int i, j, k;
  3. i = 0; j = 9;
  4. do {
  5.         k =  (i + j) /2;
  6.         if( Y[k] < x)  i = k; else j = k;
  7.     } while(Y[k] != x && i < j);
  8. if(Y[k] == x) printf ("x is in the array ") ;
  9. else printf (" x is not in the array ") ;
  10. }

`

On which of the following contents of Y and x does the program fail?

The time taken by binary search algorithm to search a key in a sorted array of n elements is

There are 11 questions to complete.

Take a part in the ongoing discussion