Which of the following search algorithms require the input to be sorted in ascending order?
Which sorting algorithm has the worst-case time complexity of O(n^2)?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following is a stable sorting algorithm?
Which search algorithm has a time complexity of O(log n)?
Which sorting algorithm is known for its in-place sorting property?
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;
}
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;
}
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;
}
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;
}
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;
}
Which of the following sorting algorithms has the best average-case time complexity?
Which of the following search algorithms can be applied on a singly linked list?
Which sorting algorithm is the most suitable for sorting a large collection of elements with a small range of values?
Which sorting algorithm is an example of an in-place and stable sorting algorithm?
Which of the following is true about binary search?