Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the low pointer to start of the array.
DSA C++
int low = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting low at 1 instead of 0.
Starting low at -1 which is invalid index.
✗ Incorrect
The low pointer should start at index 0 to begin partitioning from the start.
2fill in blank
mediumComplete the code to swap elements at indices i and low.
DSA C++
std::swap(arr[[1]], arr[low]);Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with high instead of low.
Swapping with pivot index which is not used here.
✗ Incorrect
We swap the current element at i with the element at low to move smaller elements to the front.
3fill in blank
hardFix the error in the loop condition to process all elements.
DSA C++
while (i [1] high) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using < causes last element to be skipped.
Using > or >= reverses the loop logic.
✗ Incorrect
The loop should run while i is less than or equal to high to process all elements.
4fill in blank
hardFill both blanks to correctly update pointers after swapping smaller element.
DSA C++
std::swap(arr[i], arr[[1]]); [2]++; i++;
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing high instead of low.
Not incrementing i causing infinite loop.
✗ Incorrect
After swapping with low, increment low and i to move forward.
5fill in blank
hardFill both blanks to correctly swap and update pointers for larger elements.
DSA C++
std::swap(arr[i], arr[[1]]); [2]--; // do not increment i here
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing i after swapping with high causes skipping elements.
Swapping with low instead of high.
✗ Incorrect
Swap with high, decrement high pointer, and do not increment i to recheck swapped element.
