• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Searching Algorithm with Answers

Question 11

Consider the following program that attempts to locate an element x in a sorted array a[ ] using binary search. Assume N>1. The program is erroneous. Under what conditions does the program fail?

var i,j,k: integer;  x: integer;
    a: array; [1....N] of integer;
begin	i:= 1; j:= N;
repeat	
    k:(i+j) div 2;
    if a[k] < x then i:= k 
    else j:= k 
until (a[k] = x) or (i >= j);
    
if (a[k] = x) then
    writeln (\'x is in the array\')
else
    writeln (\'x is not in the array\')
end;
  • x is the last element of the array a[]

  • x is greater than all elements of the array a[]

  • Both of the Above

  • x is less than the last element of the array a[]

Question 12

The recurrence relation that arises in relation with the complexity of binary search is:

  • T(n) = 2T(n/ 2) + k , where k is constant

  • T(n) = T(n / 2) + k , where k is constant

  • T(n) = T(n / 2) + log n

  • T(n) = T(n / 2) + n

Question 13

Suppose there are 11 items in sorted order in an array. How many searches are required on the average, if binary search is employed and all searches are successful in finding the item?

  • 3.00

  • 3.46

  • 2.81

  • 3.33

Question 14

Which of the following statements is true for Branch - and - Bound search?
  • Underestimates of remaining distance may cause deviation from optimal path.
  • Overestimates can\'t cause right path to be overlooked.
  • Dynamic programming principle can be used to discard redundant partial paths.
  • All of the above

Question 15

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

  • O ( log2n )

  • O ( n )

  • O ( n log2n )

  • O ( n^2)

Question 16

Match the following:

List - IList - II
(a) Sequential Search(i) Dynamic programming principle
(b)Branch - and - bound(ii) repeatedly double index
(c) Exponential Search(iii) O(LogN)
(d) Binary Search(iv)O(N)

codes:

 (a)(b)(c)(d)
(1)(i)(iv)(iii)(ii)
(2)(iv)(i)(ii)(iii)
(3)(i)(iv)(ii)(iii)
(4)(iv)(ii)(i)(iii)
  • (1)

  • (2)

  • (3)

  • (4)

Question 17

Number of comparisons required for an unsuccessful search of an element in a sequential search, organized, fixed length, symbol table of length L is
  • L
  • L/2
  • (L+1)/2
  • 2L

Question 18

The necessary condition for using binary search in an array is :-

  • The array should not be too long

  • The array should of more size

  • The array should be sorted 

  • None of these

Question 19

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

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?

  • Y is [1 2 3 4 5 6 7 8 9 10] and x < 10

  • Y is [1 3 5 7 9 11 13 15 17 19] and x < 1

  • Y is [2 2 2 2 2 2 2 2 2 2] and x > 2

  • Y is [2 4 6 8 10 12 14 16 18 20] and 2 < x < 20 and x is even

Question 20

what is the name of the below searching Algorithm?

C++
int function(vector<int> arr,int x){
	int n = arr.size();
	
	if(n == 0)
		return -1;

	// Find range for binary search by repeatedly doubling i
	int i = 1;
	while(i < n and arr[i] < x)
		i *= 2;

	// Perform binary search on the range [i/2, min(i, n-1)]
	int left = i /2;
	int right = min(i, n-1);

	while(left <= right){
		int mid = (left + right)/2;
		
		if(arr[mid] == x) return mid;
		else if(arr[mid] < x) left = mid + 1;
		else right = mid - 1;
	}

	return -1;
}
  • Linear Search

  • Sequential Search

  • Jump  Search

  • Exponential Search

There are 28 questions to complete.

Last Updated :
Take a part in the ongoing discussion