Complete the code to declare a stable sorting algorithm function name.
void [1](int arr[], int n);mergeSort is a stable sorting algorithm, meaning it keeps the order of equal elements.
Complete the code to compare two elements for stability in sorting.
if (arr[i] [1] arr[j]) { swap(&arr[i], &arr[j]); }
Using > ensures we swap only when the left element is greater, preserving stability if implemented carefully.
Fix the error in the code to maintain stability during insertion sort.
while (j >= 0 && arr[j] [1] key) { arr[j + 1] = arr[j]; j--; }
Using > ensures only elements greater than the key move, preserving stability.
Fill both blanks to create a condition that chooses a sorting algorithm based on data size.
if (n [1] 1000) { [2](arr, n); } else { quickSort(arr, 0, n - 1); }
For small arrays (<= 1000), insertionSort is efficient and stable; otherwise, quickSort is used.
Fill all three blanks to implement a stable merge step in merge sort.
while (i < n1 && j < n2) { if (L[i] [1] R[j]) { arr[k] = L[i]; i[2]; } else { arr[k] = R[j]; j[3]; } k++; }
Using <= ensures stability by choosing left element first if equal. Increment i and j with ++ after assignment.
