Welcome to the Sorting and Searching MCQs Page
Dive deep into the fascinating world of Sorting and Searching with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Sorting and Searching, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Sorting and Searching, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.
Check out the MCQs below to embark on an enriching journey through Sorting and Searching. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.
Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Sorting and Searching. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!
Sorting and Searching MCQs | Page 15 of 24
Explore more Topics under Data Structures and Algorithms
a)
public int linearSearch(int arr[],int key,int size)
{
int index = -1;
int i = 0;
while(size > 0)
{
if(data[i] == key)
{
index = i;
}
if(data[i] > key))
{
index = i;
break;
}
i++;
}
return index;
}
b)
public int linearSearch(int arr[],int key,int size)
{
int index = -1;
int i = 0;
while(size > 0)
{
if(data[i] == key)
{
index = i;
}
if(data[i] > key))
{
break;
}
i++;
}
return index;
}
c)
public int linearSearch(int arr[],int key,int size)
{
int index = -1;
int i = 0;
while(size > 0)
{
if(data[i] == key)
{
break;
}
if(data[i] > key))
{
index = i;
}
i++;
}
return index;
}
d) None of the mentioned
a)
public void linSearch(int[] arr, int first, int last, int key)
{
if(first == last)
{
System.out.print("-1");
}
else
{
if(arr[first] == key)
{
System.out.print(first);
}
else
{
linSearch(arr, first+1, last, key);
}
}
}
b)
public void linSearch(int[] arr, int first, int last, int key)
{
if(first == last)
{
System.out.print("-1");
}
else
{
if(arr[first] == key)
{
System.out.print(first);
}
else
{
linSearch(arr, first+1, last-1, key);
}
}
}
c)
public void linSearch(int[] arr, int first, int last, int key)
{
if(first == last)
{
System.out.print("-1");
}
else
{
if(arr[first] == key)
{
System.out.print(last);
}
else
{
linSearch(arr, first+1, last, key);
}
}
}
d)
public void linSearch(int[] arr, int first, int last, int key)
{
if(first == last)
{
System.out.print("-1");
}
else
{
if(arr[first] == key)
{
System.out.print(first);
}
else
{
linSearch(arr, first+1, last+1, key);
}
}
}
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]);
}
}
}
a)
public int findPopular(int[] a)
{
if (a == null || a.length == 0)
return 0;
Arrays.sort(a);
int previous = a[0];
int popular = a[0];
int count = 1;
int maxCount = 1;
for (int i = 1; i < a.length; i++)
{
if (a[i] == previous)
count++;
else
{
if (count > maxCount)
{
popular = a[i-1];
maxCount = count;
}
previous = a[i];
count = 1;
}
}
return count > maxCount ? a[a.length-1] : popular;
}
b)
public int findPopular(int[] a)
{
if (a == null || a.length == 0)
return 0;
Arrays.sort(a);
int previous = a[0];
int popular = a[0];
int count = 1;
int maxCount = 1;
for (int i = 1; i < a.length; i++)
{
if (a[i] == previous)
count++;
else
{
if (count > maxCount)
{
popular = a[i];
maxCount = count;
}
previous = a[i];
count = 1;
}
}
return count > maxCount ? a[a.length-1] : popular;
}
c)
public int findPopular(int[] a)
{
if (a == null || a.length == 0)
return 0;
Arrays.sort(a);
int previous = a[0];
int popular = a[0];
int count = 1;
int maxCount = 1;
for (int i = 1; i < a.length; i++)
{
if (a[i+1] == previous)
count++;
else
{
if (count > maxCount)
{
popular = a[i-1];
maxCount = count;
}
previous = a[i];
count = 1;
}
}
return count > maxCount ? a[a.length-1] : popular;
}
d) None of the mentioned
a)
public static int recursive(int arr[], int low, int high, int key)
{
int mid = low + (high - low)/2;
if(arr[mid] == key)
{
return mid;
}
else if(arr[mid] < key)
{
return recursive(arr,mid+1,high,key);
}
else
{
return recursive(arr,low,mid-1,key);
}
}
b)
public static int recursive(int arr[], int low, int high, int key)
{
int mid = low + (high + low)/2;
if(arr[mid] == key)
{
return mid;
}
else if(arr[mid] < key)
{
return recursive(arr,mid-1,high,key);
}
else
{
return recursive(arr,low,mid+1,key);
}
}
c)
public static int recursive(int arr[], int low, int high, int key)
{
int mid = low + (high - low)/2;
if(arr[mid] == key)
{
return mid;
}
else if(arr[mid] < key)
{
return recursive(arr,mid,high,key);
}
else
{
return recursive(arr,low,mid-1,key);
}
}
d) None of the mentioned
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!