Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the gap for Shell Sort.
DSA Rust
let mut gap = [1] / 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr.len() / 2 which makes the gap a quarter of the length.
Using length minus one which is off by one.
✗ Incorrect
Shell Sort starts with a gap of half the array length.
2fill in blank
mediumComplete the code to reduce the gap in each iteration.
DSA Rust
gap = [1] / 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using the array length again instead of the current gap.
Subtracting 1 instead of dividing.
✗ Incorrect
The gap is reduced by half each time until it reaches zero.
3fill in blank
hardFix the error in the inner loop condition to avoid index out of bounds.
DSA Rust
while j >= [1] && arr[j - [1]] > temp {
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 or 0 causing index underflow.
Using array length which is too large.
✗ Incorrect
The loop checks elements gap positions behind, so j must be at least gap.
4fill in blank
hardFill both blanks to correctly shift elements during insertion sort step.
DSA Rust
arr[j] = arr[j [1] [2]];
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of subtraction.
Using 1 instead of gap for shifting.
✗ Incorrect
Elements are shifted by subtracting the gap to move them forward.
5fill in blank
hardFill all three blanks to complete the insertion of temp element.
DSA Rust
let mut j = i; while j >= [1] && arr[j - [2]] > temp { arr[j] = arr[j - [3]]; j -= [3]; } arr[j] = temp;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of gap causing wrong shifts.
Using array length causing index errors.
✗ Incorrect
The insertion shifts elements by gap until the right position is found.
