0
0
DSA Goprogramming~10 mins

Quick Sort Algorithm in DSA Go - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aj
Bpivot
Clow
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with the pivot index instead of i.
Using j twice in the swap.
2fill in blank
medium

Complete the code to choose the pivot element for partitioning.

DSA Go
pivot := arr[[1]]
Drag options to blanks, or click blank then click option'
Alow
Bhigh
Cmid
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the pivot as low or mid index incorrectly.
Using a fixed index like 0 regardless of segment.
3fill in blank
hard

Fix 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'
A<
B<=
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes the pivot to be included in the loop.
Using > or >= causes the loop to never run.
4fill in blank
hard

Fill 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'
Alow
Bhigh
Cpi
D0
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.
5fill in blank
hard

Fill 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'
Alow
Bhigh
Dpivot
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].