You can prepare effectively for Software Development DSA in C++ with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Searching and Sorting - 2". These 15 questions have been designed by the experts with the latest curriculum of Software Development 2026, to help you master the concept.
Test Highlights:
Sign up on EduRev for free to attempt this test and track your preparation progress.
Which of the following search algorithms require the input to be sorted in ascending order?
Detailed Solution: Question 1
Which sorting algorithm has the worst-case time complexity of O(n^2)?
Detailed Solution: Question 2
Which of the following is a stable sorting algorithm?
Detailed Solution: Question 3
Which search algorithm has a time complexity of O(log n)?
Detailed Solution: Question 4
Which sorting algorithm is known for its in-place sorting property?
Detailed Solution: Question 5
What will be the output of the following code snippet?
#include <iostream>
using namespace std;
void selectionSort(int arr[], int size) {
for (int i = 0; i < size - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < size; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
swap(arr[i], arr[minIndex]);
}
}
int main() {
int arr[] = {5, 2, 9, 1, 7};
int size = sizeof(arr) / sizeof(arr[0]);
selectionSort(arr, size);
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
return 0;
}
Detailed Solution: Question 6
What will be the output of the following code snippet?
#include <iostream>
using namespace std;
void bubbleSort(int arr[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
swap(arr[j], arr[j + 1]);
}
}
}
}
int main() {
int arr[] = {3, 8, 1, 6, 4};
int size = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, size);
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
return 0;
}
Detailed Solution: Question 7
What will be the output of the following code snippet?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int low, int high, int target) {
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == target) {
return mid;
}
if (arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return -1;
}
int main() {
int arr[] = {2, 5, 8, 12, 16};
int size = sizeof(arr) / sizeof(arr[0]);
int target = 8;
int index = binarySearch(arr, 0, size - 1, target);
cout << "Element found at index: " << index;
return 0;
}
Detailed Solution: Question 8
What will be the output of the following code snippet?
#include <iostream>
using namespace std;
void insertionSort(int arr[], int size) {
for (int i = 1; i < size; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main() {
int arr[] = {7, 3, 9, 2, 5};
int size = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, size);
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
return 0;
}
Detailed Solution: Question 9
What will be the output of the following code snippet?
#include <iostream>
using namespace std;
int linearSearch(int arr[], int size, int target) {
for (int i = 0; i < size; i++) {
if (arr[i] == target) {
return i;
}
}
return -1;
}
int main() {
int arr[] = {4, 9, 2, 7, 5};
int size = sizeof(arr) / sizeof(arr[0]);
int target = 7;
int index = linearSearch(arr, size, target);
cout << "Element found at index: " << index;
return 0;
}
Detailed Solution: Question 10
Which of the following sorting algorithms has the best average-case time complexity?
Detailed Solution: Question 11
Which of the following search algorithms can be applied on a singly linked list?
Detailed Solution: Question 12
Which sorting algorithm is the most suitable for sorting a large collection of elements with a small range of values?
Detailed Solution: Question 13
Which sorting algorithm is an example of an in-place and stable sorting algorithm?
Detailed Solution: Question 14
Which of the following is true about binary search?
Detailed Solution: Question 15
152 videos|118 docs|24 tests |