Embercode
✕
Heaps and Priority QueuesQuick quiz

Kth and closest points

8 questions. Covers K closest points with a size-k heap.

Questions 1 to 5 of 8

  1. 1. The kth largest value can be found with a heap of size k. Which heap should you keep, and why?
  2. 2. Two points are both at squared distance 4, and k = 1. The point (2, 0) is read first and (0, 2) second. Which point does kClosest keep, and why?
  3. 3. The lesson's large test reads 200,000 points for k = 5. The heap method costs about log2(k) steps for each point, as the lesson counts it. What is log2(5), rounded to two decimal places?

    Type a number.

  4. 4. Which statements about the costs in this lesson are true? Choose all that apply.

    Pick every answer that is true.

  5. 5. What does this program print? ``cpp #include <functional> #include <iostream> #include <queue> #include <vector> int main() { std::priority_queue<int, std::vector<int>, std::greater<int>> heap; for (int x : {4, 1, 7, 3, 8, 5}) { heap.push(x); if (heap.size() > 3) { heap.pop(); } } std::cout << heap.top() << ' ' << heap.size() << '\n'; } ``

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.