Complete the code to start the outer loop from the second element in the array.
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; }
The insertion sort starts from the second element (index 1) because the first element is considered sorted.
Complete the code to correctly shift elements greater than the key to the right.
while (j >= 0 && arr[j] [1] key) { arr[j + 1] = arr[j]; j--; }
We shift elements that are greater than the key to the right to make space for the key.
Fix the error in the code to place the key at the correct position after shifting.
arr[[1]] = key;After shifting, the correct position for the key is at index j + 1.
Fill both blanks to create a function header and call for insertion sort.
[1] 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[] = {12, 11, 13, 5, 6}; int n = sizeof(arr) / sizeof(arr[0]); [2]; return 0; }
The function returns nothing, so use 'void'. The call passes array and size in correct order.
Fill all three blanks to print the sorted array after insertion sort.
for (int [1] = 0; [2] < n; [3]++) { printf("%d ", arr[i]); }
The loop variable is 'i' used consistently to print all elements.
