0
0
DSA C++programming~10 mins

Selection Sort Algorithm in DSA C++ - 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 C++
int temp = arr[i];
arr[i] = arr[[1]];
arr[[1]] = temp;
Drag options to blanks, or click blank then click option'
Aj
Bi
CminIndex
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with the wrong index like j or i itself.
Forgetting to use a temporary variable for swapping.
2fill in blank
medium

Complete the code to find the minimum element's index in the unsorted part of the array.

DSA C++
for (int j = i + 1; j < n; j++) {
    if (arr[j] < arr[[1]]) {
        minIndex = j;
    }
}
Drag options to blanks, or click blank then click option'
AminIndex
Bi
Cj
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with arr[i] instead of arr[minIndex].
Using j as the index to compare with itself.
3fill in blank
hard

Fix the error in the loop condition to avoid going out of array bounds.

DSA C++
for (int i = 0; i < [1]; i++) {
    // selection sort logic
}
Drag options to blanks, or click blank then click option'
An
Bn / 2
Cn + 1
Dn - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using i < n causes unnecessary iteration.
Using i < n + 1 causes out of bounds error.
4fill in blank
hard

Fill both blanks to complete the inner loop and update the minimum index correctly.

DSA C++
for (int j = [1]; j < n; j++) {
    if (arr[j] < arr[[2]]) {
        minIndex = j;
    }
}
Drag options to blanks, or click blank then click option'
Ai + 1
Bi
CminIndex
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Starting inner loop from 0 or i instead of i + 1.
Comparing with arr[i] instead of arr[minIndex].
5fill in blank
hard

Fill all three blanks to complete the code that populates a std::map mapping elements greater than 10 to their indices.

DSA C++
std::map<int, int> result;
for (int i = 0; i < arr.size(); i++) {
    if (arr[i] [3] 10) {
        result[[1]] = [2];
    }
}
Drag options to blanks, or click blank then click option'
Aarr[i]
Bi
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Swapping key and value in the map.