Code
The highlighted line runs next. Sift-up and sift-down steps happen inside the library's push and pop, so they stay on the push and pop lines.
X-Y plane
Max-heap (by dist²)
tree view big number = dist², small = the point
array view
Why squared distance? √ only changes the size, not the order: if a² < b² then a < b. Skipping it keeps the math in whole numbers. Why a max-heap? We need quick access to the worst of the k we're keeping. Cost: O(n log k) time, O(k) memory.
Dry-run trace
Every step as a row. Click a row to jump there.
| # | Action | point | dist² | Detail | heap (dist²) | size |
|---|