FInd an algorithm for the next problem : Given set S of n points in the 2D plane, a point (x1, y1) dominates another point (x2, y2) if x1 > x2 and y1 > y2. Find the largest set of points M such that M is a subset of S and no point of M is dominated by another point of S.
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- How to determine +/- sign when calculating diagona
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- How to measure complexity of a string?
- Select unique/deduplication in SSE/AVX
- How to smooth the blocks of a 3D voxel world?
Sort all points by increasing x coordinates. If two points have the same x coordinate, sort them by decreasing y coordinates. Now, it can be shown that a subset of points is non-dominated if and only if their y coordinates are non-increasing in our sorted sequence, meaning each y coordinate is less than or equal to the previous one in the subsequence.
So the algorithm would be:
This gives the largest possible set in O(n*logn).
There is a divide and conquer algorithm which does this in O(n*logn) time.
Let's divide the points into two halfs, of size n/2 each, based on their x co-ordinates. We find the non-dominated point set in both the halfs. You need to observe that all the non-dominated points found in the right half will exist in our final list.
With this observation we can write our combine step, remove all the non-dominated points in the left half which have y co-ordinate less than highest y co-ordinate of the point in the non-dominated set in the right half. We have the set of non-dominated points.
Algorithm:
Equation for time :
You can improve this further to O(n*logH) where H is the number of non-dominated points, it requires more insight into the problem and it is a good extension for you to work on.