Complete the code to initialize the gap for Shell Sort.
int n = arr.Length;
int gap = [1];The initial gap in Shell Sort is usually set to half the array length.
Complete the code to reduce the gap in each iteration of Shell Sort.
while (gap > 0) { // sorting logic gap = [1]; }
The gap is reduced by half each time until it reaches zero.
Fix the error in the inner loop condition to avoid index out of range.
for (int i = gap; i < [1]; 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; }
The loop must run until i is less than the array length to cover all elements.
Fill both blanks to correctly implement the inner while loop condition and update index.
while (j [1] gap && arr[j [2] gap] > temp) { arr[j] = arr[j - gap]; j -= gap; }
The condition checks if j is at least gap and compares arr[j - gap] with temp.
Fill all three blanks to complete the Shell Sort method header and array parameter.
public static void [1](int[] [2]) { int n = [2].Length; int gap = n / 2; while (gap > 0) { for (int i = gap; i < n; i++) { int temp = [2][i]; int j = i; while (j >= gap && [2][j - gap] > temp) { [2][j] = [2][j - gap]; j -= gap; } [2][j] = temp; } gap /= 2; } }
The method is named ShellSort and the array parameter is commonly named arr.
