Complete the code to swap two elements in the array.
int temp = arr[i]; arr[i] = arr[[1]]; arr[[1]] = temp;
We swap the element at index i with the element at the minIndex to place the smallest element found at the correct position.
Complete the code to find the minimum element's index in the unsorted part of the array.
for (int j = i + 1; j < n; j++) { if (arr[j] < arr[[1]]) { minIndex = j; } }
We compare arr[j] with arr[minIndex] to find the smallest element's index in the unsorted part.
Fix the error in the loop condition to avoid going out of array bounds.
for (int i = 0; i < [1]; i++) { // selection sort logic }
i < n causes unnecessary iteration.i < n + 1 causes out of bounds error.The outer loop runs until n - 1 because the last element will already be sorted after previous passes.
Fill both blanks to complete the inner loop and update the minimum index correctly.
for (int j = [1]; j < n; j++) { if (arr[j] < arr[[2]]) { minIndex = j; } }
The inner loop starts from i + 1 to check the unsorted part, and we compare with arr[minIndex] to find the smallest element.
Fill all three blanks to complete the code that populates a std::map mapping elements greater than 10 to their indices.
std::map<int, int> result; for (int i = 0; i < arr.size(); i++) { if (arr[i] [3] 10) { result[[1]] = [2]; } }
We map each element arr[i] to its index i only if the element is greater than 10.