Sort all points by distance, take the first k.
Sorting takes . But you only need the k closest, not the full sorted order.
If k is much smaller than n, can you avoid sorting everything?
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
The trap
Sort all points by distance, take the first k.
Sorting takes . But you only need the k closest, not the full sorted order.
If k is much smaller than n, can you avoid sorting everything?