Vidyalelo
Data Structure · all questions

Searching Algorithms
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

132

Questions

5/7

Page

Pick an option on a question to see the right answer and solution.

Given an input arr = {2, 5, 7, 99, 899}; key = 899; What is the level of recursion?

Select an option to see the answer and solution.

Exponential search performs better than binary search when the element being searched is present near the starting point of the array.

Select an option to see the answer and solution.

What is the best case runtime of linear search(recursive) algorithm on an ordered set of elements?

Select an option to see the answer and solution.

What does the following piece of code do?
for (int i = 0; i < arr.length-1; i++)
{
    for (int j = i+1; j < arr.length; j++)
    {
        if( (arr[i].equals(arr[j])) && (i != j) )
        {
            System.out.println(arr[i]);
        }
    }
}

Select an option to see the answer and solution.

In which of the cases uniform binary search fails compared to binary search?

Select an option to see the answer and solution.

What is the time complexity of uniform binary search?

Select an option to see the answer and solution.

What is the worst case complexity of binary search using recursion?

Select an option to see the answer and solution.

Which of the following searching algorithm is fastest when the input array is sorted and has uniformly distributed values?

Select an option to see the answer and solution.

Best case of the exponential search will have time complexity of?

Select an option to see the answer and solution.

Exponential search has . . . . . . . .

Select an option to see the answer and solution.

Which of the following is a disadvantage of linear search?

Select an option to see the answer and solution.

What is the advantage of recursive approach than an iterative approach?

Select an option to see the answer and solution.

Which of the following is the most desirable condition for interpolation search?

Select an option to see the answer and solution.

Given delta[4] is a global array and number of elements in the sorted array is 10, what are the values in the delta array?

Select an option to see the answer and solution.

Which of the following false about Jump Search?

Select an option to see the answer and solution.

Which of the following is not an application of binary search?

Select an option to see the answer and solution.

In which of the following case jump search will be preferred over binary search?

Select an option to see the answer and solution.

The array is as follows: 1, 2, 3, 6, 8, 10. Given that the number 17 is to be searched. At which call it tells that there's no such element? (By using linear search(recursive) algorithm)

Select an option to see the answer and solution.

What will be the worst case time complexity of the following code?
#include<bits/stdc++.h> 
using namespace std; 
 
void func(char* str2, char* str1) 
{ 
	int m = strlen(str2); 
	int n = strlen(str1); 
	for (int i = 0; i <= n - m; i++) 
        { 
		int j; 
 
 
		for (j = 0; j < m; j++) 
			if (str1[i + j] != str2[j]) 
				break; 
 
		if (j == m) 
			cout << i << endl; 
	} 
} 
 
int main() 
{ 
	char str1[] = "1253234"; 
	char str2[] = "323"; 
	func(str2, str1); 
	return 0; 
}

Select an option to see the answer and solution.

What will be the best case time complexity of the following code?
#include<bits/stdc++.h> 
using namespace std; 
void func(char* str2, char* str1) 
{ 
	int m = strlen(str2); 
	int n = strlen(str1); 
 
	for (int i = 0; i <= n - m; i++) 
        { 
		int j; 
 
 
		for (j = 0; j < m; j++) 
			if (str1[i + j] != str2[j]) 
				break; 
 
		if (j == m) 
			cout << i << endl; 
	} 
} 
 
int main() 
{ 
	char str1[] = "1253234"; 
	char str2[] = "323"; 
	func(str2, str1); 
	return 0; 
}

Select an option to see the answer and solution.