0

The maximal points of a set are points that have x and y-coordinates which are greater than or equal to the x and y coordinates of every other point. I have a set whose points are sorted by increasing x-coordinates.

This needs to be done recursively/divide-and-conquer.

My approach was akin to:
1. Go to the end of the array to find the coordinates with the largest x-coordinate
2. Do a merge sort on the y-values of these x-coordinates
3. Go to the end of that sorted array, the largest y-values found here are the maximal points.

However, this would be O(n log n) due to the merge sort and I was told that it is possible to write code that runs in O(n). Can anyone provide recursive pseudocode which could do this in linear time?

Julio Revka
  • 169
  • 3
  • 11
  • Note: Sets are generally not considered orderable. This is about a sequence/collection, where the elements are guaranteed unique as a precondition. – user2864740 Sep 29 '14 at 05:11
  • I do not understand, what exactly must be greater? The sum of (x,y), euclidian distance sqrt(x^2 + y^2)? – Jean Logeart Sep 29 '14 at 05:14
  • Basically, just assume you have an array containing xy-coordinates and you are trying to find the greatest coordinates. i.e. The coordinates which has the largest x and y-value compared to all the others. Not the sum or distance, but straight up, the largest x and largest y. – Julio Revka Sep 29 '14 at 05:17
  • I am fairly sure that "recursively/divide-and-conquer" is a misunderstanding on your part. I also am sure that your definition of "maximal points" should be, "no point has a larger x and y coordinate". My only remaining hint for your homework is "start with the largest x and work backwards." – btilly Sep 29 '14 at 05:18
  • So you are asking how to find a maximal element in an unsorted array in O(n). Are you sure you don't already know how to do this? – n. m. could be an AI Sep 29 '14 at 05:27
  • 1
    largest x and y? so what will be return if you have only two points (1,3) and (3,1) ? what should be the largest? – Pham Trung Sep 29 '14 at 05:46

0 Answers0