If you sort the points along the X axis, then you must do a binary search to find the leftmost (smallest X value) that is in the rectangle.
Do another binary search to find the largest in the rectangle (the largest value of X).
All points in the sorted list between these two points will be within the left edge of the rectangle, even if you have not checked most of them!
Repeat the same process along the vertical / y-axis.
Two binary searches on the X axis should be equal to O (logN).
Same thing with two binary searches along the y axis.
O (4 logN) == O (log N)In the end, there will still be some kind of merger, I'm not immediately sure.
source share