• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Searching Algorithm with Answers

Question 1

Linear search is also called------

  • Random Search

  • Sequential search

  • Perfect search

  • None

Question 2

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

  • T(n) = 2T(n/2) + O(1) and T(1) = T(0) = O(1)

  • T(n) = T(n-1) + O(1) and T(1) = T(0) = O(1)

  • T(n) = T(n/2) + O(1) and T(1) = T(0) = O(1)

  • T(n) = T(n-2) + O(1) and T(1) = T(0) = O(1)

Question 3

Given a sorted array of integers, what can be the minimum worst-case time complexity to find ceiling of a number x in given array? The ceiling of an element x is the smallest element present in array which is greater than or equal to x. Ceiling is not present if x is greater than the maximum element present in array. For example, if the given array is {12, 67, 90, 100, 300, 399} and x = 95, then the output should be 100.

  • O(loglogn)

  • O(n)

  • O(log(n))

  • O(log(n) * log(n))

Question 4

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. }

In the above question, the correction needed in the program to make it work properly is (GATE CS 2008)

  • Change line 6 to: if (Y[k] < x) i = k + 1; else j = k-1;

  • Change line 6 to: if (Y[k] < x) i = k - 1; else j = k+1;

  • Change line 6 to: if (Y[k] <= x) i = k; else j = k;

  • Change line 7 to: } while ((Y[k] == x) && (i < j));

Question 5

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

  •    T(n) = T(n/3) + 4, T(1) = 1

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

  •   T(n) = T(n + 2) + 2,  T(1) = 1

  •   T(n) = T(n - 2) + 2,  T(1) = 1

Question 6

The increasing order of performance  of the searching algorithms are:

  • linear search  <  jump search  <  binary search

  • linear search  >  jump search  <  binary search

  • linear search  <  jump search  >  binary search

  • linear search  >  jump search  >  binary search

Question 7

The average case occurs in the Linear Search Algorithm when:
  • The item to be searched is in some where middle of the Array
  • The item to be searched is not in the array
  • The item to be searched is in the last of the array
  • The item to be searched is either in the last or not in the array

Question 8

Consider a sorted array of n numbers and a number x. What would be the time complexity of the best known algorithm to find a triplet with sum equal to x. For example, arr[] = {1, 5, 10, 15, 20, 30}, x = 40. Then there is a triplet {5, 15, 20} with sum 40.

  • O(n)

  • O(n^2)

  • O(n Log n)

  • O(n^3)

Question 9

Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending order. 

C
int ProcessArray(int *listA, int x, int n)
{
    int i, j, k;
    i = 0;
    j = n-1;
    do
    {
        k = (i+j)/2;
        if (x <= listA[k])
            j = k-1;
        if (listA[k] <= x)
            i = k+1;
    }
    while (i <= j);
    if (listA[k] == x)
        return(k);
    else
        return -1;
}

Which one of the following statements about the function ProcessArray is CORRECT?

  • It will run into an infinite loop when x is not in listA.

  • It is an implementation of binary search.

  • It will always find the maximum element in listA.

  • It will return −1 even when x is present in listA.

Question 10

The average number of key comparisons done in a successful sequential search in a list of length n is

  • log n

  • (n-1)/2

  • n/2

  • (n+1)/2

There are 28 questions to complete.

Last Updated :
Take a part in the ongoing discussion