0
0
DSA C++programming~10 mins

Comparison Based vs Non Comparison Based Sorting in DSA C++ - Interactive Comparison Practice

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

Complete the code to declare a vector of integers named 'arr'.

DSA C++
std::vector<int> [1];
Drag options to blanks, or click blank then click option'
Avec
Barr
Clist
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array' or 'list' instead of 'arr'.
2fill in blank
medium

Complete the code to sort the vector 'arr' using a comparison based sorting algorithm.

DSA C++
std::sort(arr.[1](), arr.end());
Drag options to blanks, or click blank then click option'
Abegin
Bstart
Cfirst
Dfront
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start()' or 'first()' which are not valid vector methods.
3fill in blank
hard

Fix the error in the code to perform counting sort on the vector 'arr'.

DSA C++
std::vector<int> count(max_val + 1, 0);
for (int num : arr) {
    count[[1]]++;
}
Drag options to blanks, or click blank then click option'
Anum
Barr
Ci
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'arr' or 'i' which are not the current element in the loop.
4fill in blank
hard

Fill both blanks to complete the code that reconstructs the sorted array from the count array.

DSA C++
int index = 0;
for (int i = 0; i <= max_val; i++) {
    while (count[[1]] > 0) {
        arr[[2]] = i;
        count[i]--;
        index++;
    }
}
Drag options to blanks, or click blank then click option'
Ai
Bindex
Ccount
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count' or 'num' instead of 'i' for the first blank.
5fill in blank
hard

Fill all three blanks to complete the code that creates a map of element frequencies using a non-comparison based approach.

DSA C++
std::unordered_map<int, int> freq;
for (int [1] : arr) {
    freq[[2]] = freq[[3]] + 1;
}
Drag options to blanks, or click blank then click option'
Anum
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for loop and map keys.