Embercode
✕
Maps and Sets (C++)Quick quiz

O(1) random set

7 questions. Covers Insert, delete and random pick in O(1).

Questions 1 to 5 of 7

  1. 1. What does this program print? ``cpp #include <cstddef> #include <iostream> #include <vector> int main() { std::vector<int> values = {10, 20, 30, 40}; std::size_t hole = 1; values[hole] = values.back(); values.pop_back(); for (int v : values) std::cout << v << ' '; std::cout << '\n'; } ``
  2. 2. What does this program print? ``cpp #include <cstddef> #include <iostream> #include <vector> int main() { std::vector<int> values = {10, 20, 30}; std::size_t hole = 2; values[hole] = values.back(); values.pop_back(); std::cout << "size " << values.size() << '\n'; for (int v : values) std::cout << v << ' '; std::cout << '\n'; } ``
  3. 3. Which statements about the RandomSet from this lesson are true? Select all that apply.

    Pick every answer that is true.

  4. 4. Which statements about the steps of remove are true? Select all that apply.

    Pick every answer that is true.

  5. 5. Why can remove avoid shifting values to fill the gap?

5 question(s) left on this page.