Embercode
✕
SortingQuick quiz

Partial sorting

6 questions. Covers Partial sorting.

Questions 1 to 5 of 6

  1. 1. What does this code print? ``cpp vector<int> v = {9, 4, 7, 1, 8}; partial_sort(v.begin(), v.begin() + 2, v.end()); cout << v[0] << ' ' << v[1] << '\n'; ``
  2. 2. What does best hold after this code runs? ``cpp vector<int> src = {3, 9, 1, 7}; vector<int> best(3); partial_sort_copy(src.begin(), src.end(), best.begin(), best.end()); ``
  3. 3. After nth_element(v.begin(), v.begin() + 2, v.end()) runs on 5 2 8 1 9, which statement is guaranteed to be true?
  4. 4. Roughly how many comparisons does std::nth_element need, on average, to place one chosen value in its correct position in a list of n values?
  5. 5. A program needs the top 5 scores in descending order, and the original vector must stay unchanged. Which call fits?

5 question(s) left on this page.