Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to swap two elements in the array.
DSA Go
arr[[1]], arr[j] = arr[j], arr[[1]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with the pivot index instead of i.
Using j twice in the swap.
✗ Incorrect
Swapping elements at positions i and j is needed to reorder elements around the pivot.
2fill in blank
mediumComplete the code to choose the pivot element for partitioning.
DSA Go
pivot := arr[[1]] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the pivot as low or mid index incorrectly.
Using a fixed index like 0 regardless of segment.
✗ Incorrect
The pivot is chosen as the element at the high index for partitioning.
3fill in blank
hardFix the error in the partition loop condition.
DSA Go
for j := low; j [1] high; j++ {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes the pivot to be included in the loop.
Using > or >= causes the loop to never run.
✗ Incorrect
The loop runs from low up to but not including high, so j < high is correct.
4fill in blank
hardFill both blanks to complete the recursive quicksort calls.
DSA Go
quickSort(arr, [1], pi-1) quickSort(arr, pi+1, [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pi instead of pi-1 or pi+1 causes infinite recursion.
Using 0 instead of high for right side.
✗ Incorrect
The recursive calls sort the left part from low to pi-1 and right part from pi+1 to high.
5fill in blank
hardFill all three blanks to complete the partition function return and variable initialization.
DSA Go
func partition(arr []int, [1] int, [2] int) int { pivot := arr[[3]] i := [1] - 1 for j := [1]; j < [2]; j++ { if arr[j] < pivot { i++ arr[i], arr[j] = arr[j], arr[i] } } arr[i+1], arr[[2]] = arr[[2]], arr[i+1] return i + 1 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pivot as parameter name instead of low or high.
Choosing pivot as arr[low] instead of arr[high].
✗ Incorrect
Partition uses low and high as parameters; pivot is arr[high].