Complete the code to initialize the gap for Shell Sort.
int n = sizeof(arr)/sizeof(arr[0]); int gap = [1];
The initial gap in Shell Sort is usually set to half the array size.
Complete the code to reduce the gap in each iteration of Shell Sort.
while (gap > 0) { // sorting logic here gap = [1]; }
Gap is reduced by half each iteration until it reaches zero.
Fix the error in the inner loop condition to correctly compare elements during Shell Sort.
for (int i = gap; i < n; i++) { int temp = arr[i]; int j = i; while (j >= gap && arr[j - gap] [1] temp) { arr[j] = arr[j - gap]; j -= gap; } arr[j] = temp; }
The condition arr[j - gap] > temp ensures elements are shifted if they are greater than temp.
Fill both blanks to complete the Shell Sort gap reduction and loop condition.
int gap = n / 2; while ([1] > 0) { for (int i = gap; i < n; i++) { int temp = arr[i]; int j = i; while (j >= gap && arr[j - gap] > temp) { arr[j] = arr[j - gap]; j -= gap; } arr[j] = temp; } gap = [2]; }
The outer loop continues while gap > 0, and gap is halved each iteration.
Fill all three blanks to complete the Shell Sort implementation and print the sorted array.
int n = sizeof(arr)/sizeof(arr[0]); int gap = n / 2; while (gap > 0) { for (int i = gap; i < n; i++) { int temp = arr[i]; int j = i; while (j >= gap && arr[j - gap] [1] temp) { arr[j] = arr[j - gap]; j -= gap; } arr[j] = temp; } gap = [2]; } // Print sorted array for (int k = 0; k < n; k++) { printf("%d ", arr[[3]]); }
The comparison uses '>', gap is halved each iteration, and printing uses index k.
