Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to swap two elements in the array.
DSA C#
int temp = arr[[1]]; arr[[1]] = arr[j]; arr[j] = temp;
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with pivot index instead of i or j.
Using the wrong index variable for swapping.
✗ Incorrect
We swap the element at index i with the element at index j to partition the array correctly.
2fill in blank
mediumComplete the code to choose the pivot element for partitioning.
DSA C#
int pivot = arr[[1]];Attempts:
3 left
💡 Hint
Common Mistakes
Choosing pivot as low index instead of high.
Using a fixed index like 0 regardless of segment.
✗ Incorrect
The pivot is chosen as the element at the high index to partition the array.
3fill in blank
hardFix the error in the recursive quicksort call to sort the left partition.
DSA C#
QuickSort(arr, low, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Including pivot index in left partition.
Using pivotIndex + 1 instead of pivotIndex - 1.
✗ Incorrect
We sort the left partition from low to pivotIndex - 1 to exclude the pivot element.
4fill in blank
hardFill both blanks to complete the partition method's loop and condition.
DSA C#
for (int j = [1]; j < high; j++) { if (arr[j] [2] pivot) { i++; Swap(arr, i, j); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting loop from 0 instead of low.
Using wrong comparison operator like > or <=
✗ Incorrect
The loop starts from low and checks if arr[j] is less than pivot to partition correctly.
5fill in blank
hardFill all three blanks to complete the recursive quicksort calls and base case check.
DSA C#
if (low [1] high) { int pivotIndex = Partition(arr, low, high); QuickSort(arr, low, [2]); QuickSort(arr, [3], high); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= in base case causing infinite recursion.
Including pivot index in recursive calls.
✗ Incorrect
We recurse only if low < high, then sort left and right partitions excluding the pivot.
