Problem. Given points, a list of (x, y), and k, return the k points closest to the origin (Euclidean distance),
in any order.
points = [(1, 3), (-2, 2)], k = 1 → [(-2, 2)] (√8 < √10)
points = [(3, 3), (5, -1), (-2, 4)], k = 2 → [(3, 3), (-2, 4)]
It's lesson 9.3 with a key: rank items by a computed score instead of their value. The interesting decisions are which heap (max-heap of the k best, so the worst candidate is on top), and what to compute (squared distances, no square roots).
ML context. Replace "points" with embeddings and "distance to the origin" with distance to a query embedding, and this is the retrieval step of every RAG system, recommender and k-NN classifier: score every candidate against the query and keep the k best. Brute-force scanning with a heap is exactly what a "flat" vector index does, and it's the baseline every approximate index is measured against (Change B).