0
0
DSA Goprogramming~10 mins

Comparison Based vs Non Comparison Based Sorting in DSA Go - Interactive Comparison Practice

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

Complete the code to perform a comparison-based sort using Go's built-in function.

DSA Go
import "sort"

func sortNumbers(nums []int) {
    sort.[1](nums)
}
Drag options to blanks, or click blank then click option'
AInts
Bsort
CSort
DSortNumbers
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'sort' which is the package name, not a function.
Using 'Sort' which is not a valid function in the sort package.
2fill in blank
medium

Complete the code to implement counting sort, a non-comparison based sorting algorithm.

DSA Go
func countingSort(arr []int, maxVal int) []int {
    count := make([]int, maxVal+1)
    for _, num := range arr {
        count[[1]]++
    }
    // rest of the code omitted
    return nil
}
Drag options to blanks, or click blank then click option'
Anum
Barr
Ccount
DmaxVal
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole array 'arr' as an index.
Using 'maxVal' or 'count' as an index which are not correct.
3fill in blank
hard

Fix the error in the code that attempts to compare two integers for sorting.

DSA Go
func compare(a, b int) bool {
    return a [1] b
}
Drag options to blanks, or click blank then click option'
A==
B>
C=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which is assignment, not comparison.
Using '==' which checks equality, not order.
4fill in blank
hard

Fill both blanks to complete the code that builds a frequency map for radix sort.

DSA Go
func buildFrequency(arr []int, digit int) map[int]int {
    freq := make(map[int]int)
    for _, num := range arr {
        d := (num / [1]) % [2]
        freq[d]++
    }
    return freq
}
Drag options to blanks, or click blank then click option'
Adigit
B10
Cnum
Darr
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'num' or 'arr' as divisor which are incorrect.
Using a number other than 10 for the modulus in base 10.
5fill in blank
hard

Complete the code to complete the code that creates a map of word lengths filtered by length condition.

DSA Go
func filterWords(words []string) map[int]int {
    result := make(map[int]int)
    for _, word := range words {
        if len(word) [1] 3 {
            result[[len(word)]]++
        }
    }
    return result
}
Drag options to blanks, or click blank then click option'
A>
B<=
C[
D]
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' which filters shorter or equal lengths.
Using parentheses instead of brackets for indexing.