Given a rectangle X1,Y1 and X2,Y2 such that
X1,Y1-----------------
| |
| |
----------------------X2, Y2
And given a million points ranked points P(x,y,r) where r is a random 32 bit integer...
What is the fastest way to determine the top X points inside the rectangle, based upon their ranking r.
For instance, if you have a 2d plane of size 10,000 by 10,000 and you have 1 million points scattered across it. How do I first find all the points inside the rectangle located at 200,200 to 400,400 and then how do I find the 5 points in that rect with the highest ranking.
Simple solutions, such as sort all 1 million points, then test all 1 million points to see if they are in the bounds of the rectangles (say there are 1000 of them to test), and find the top 5 points in the array, are very computationally intense.
What is the fastest way to do this, and what is the time complexity? Can this be done in less than O(N)?
Also, a quadtree approach would not work as well if the rect is the size of the entire plane... as it would just return all 1 million points that you would have to sort each time.