Complete the code to start the outer loop from the second element for insertion sort.
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 move elements greater than key one position ahead.
while (j >= 0 && arr[j] [1] key) { arr[j + 1] = arr[j]; j--; }
We move elements that are greater than the key to the right to make space for the key.
Fix the error in placing the key after shifting elements.
arr[[1]] = key;After shifting, the correct position for the key is at index j + 1.
Fill both blanks to complete the insertion sort function header and array size parameter.
void insertionSort(int arr[], int [1]) { for (int i = 1; i < [2]; 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 parameter name for array size is commonly 'n', and the loop uses 'n' to limit iterations.
Fill all three blanks to print the sorted array after insertion sort.
for (int [1] = 0; [2] < [3]; [1]++) { std::cout << arr[[1]] << " "; } std::cout << std::endl;
Use 'i' as loop variable, and 'n' as array size to print all elements.