0
0
DSA Goprogramming~10 mins

Selection 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 start the outer loop for selection sort.

DSA Go
for i := 0; i < [1]; i++ {
    // find the minimum element in unsorted array
}
Drag options to blanks, or click blank then click option'
Alen(arr) - 1
Blen(arr)
Clen(arr) + 1
Dlen(arr) / 2
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(arr) as loop limit causes index out of range error.
Using len(arr) + 1 is invalid and causes runtime error.
2fill in blank
medium

Complete the code to start the inner loop to find the minimum element.

DSA Go
minIndex := i
for j := i + 1; j < [1]; j++ {
    if arr[j] < arr[minIndex] {
        minIndex = j
    }
}
Drag options to blanks, or click blank then click option'
Alen(arr) - 1
Blen(arr) + 1
Ci + 1
Dlen(arr)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(arr) - 1 misses the last element.
Using i + 1 as upper limit causes no iteration.
3fill in blank
hard

Fix the error in swapping elements after finding the minimum index.

DSA Go
temp := arr[i]
arr[i] = arr[[1]]
arr[minIndex] = temp
Drag options to blanks, or click blank then click option'
AminIndex
B0
Cj
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with i does nothing.
Swapping with j causes undefined variable error.
4fill in blank
hard

Fill both blanks to complete the selection sort function header and return statement.

DSA Go
func [1](arr []int) []int {
    // sorting logic here
    return [2]
}
Drag options to blanks, or click blank then click option'
ASelectionSort
Barr
CsortedArr
DSort
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a variable not defined causes error.
Using wrong function name confuses readers.
5fill in blank
hard

Fill all three blanks to complete the selection sort main logic inside the function.

DSA Go
for i := 0; i < [1]; i++ {
    minIndex := i
    for j := i + 1; j < [2]; j++ {
        if arr[j] < arr[[3]] {
            minIndex = j
        }
    }
    arr[i], arr[minIndex] = arr[minIndex], arr[i]
}
Drag options to blanks, or click blank then click option'
Alen(arr) - 1
Blen(arr)
CminIndex
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using i instead of minIndex in comparison causes wrong results.
Loop limits off by one cause index errors.