Which of the following is an example of a linear search algorithm?
Which sorting algorithm has the best average-case time complexity?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following is an example of an in-place sorting algorithm?
Which of the following is an advantage of quick sort over merge sort?
Which sorting algorithm is preferred when the data is already partially sorted?
Which sorting algorithm has the worst-case time complexity of O(n2)?
What is the time complexity of merge sort in the worst case scenario?
Which of the following is an example of an unstable sorting algorithm?
What will be the output of the following code?
#include <iostream>
using namespace std;
void insertionSort(int arr[], int n) {
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}
int main() {
int arr[] = {5, 2, 4, 6, 1, 3};
int n = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, n);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
return 0;
}