views:

354

answers:

4

Given n points on the plane. No 3 are collinear.

Given the number k.

Find the subset of k points, such that the convex hull of the k points has minimum perimeter out of any convex hull of a subset of k points.

I can think of a naive method runs in O(n^k k log k). (Find the convex hull of every subset of size k and output the minimum)

I think this is a NP problem, but I can't find anything suitable for reduction to.

Anyone have ideas on this problem?

An example,

the set of n=4 points {(0,0), (0,1), (1,0), (2,2)} and k=3

Result:

{(0,0),(0,1),(1,0)}

Since this set contain 3 points the convex hull of this set is minimum out of any other sets of 3 points.

A: 

In the planar case, you can use an algorithm known as the Jarvis march, which has worst case complexity O(n^2). In this algorithm, you start building a hull at an arbitrary point and then check which point needs to be added next. Pseudocode taken from wikipedia:

jarvis(S)
   pointOnHull = leftmost point in S
   i = 0
   repeat
      P[i] = pointOnHull
      endpoint = S[0]         // initial endpoint for a candidate edge on the hull
      for j from 1 to |S|-1
         if (S[j] is on left of line from P[i] to endpoint)
            endpoint = S[j]   // found greater left turn, update endpoint
      i = i+1
      pointOnHull = endpoint
   until endpoint == P[0]      // wrapped around to first hull point

As far as I understand it, convex hulls are unique to each set of points, so there is no need to find a minimum. You just find one, and it will be the smallest one by definition.

Edit

The posted solution solves for the convex hull with the fewest number of points. Any hull with more points will have a longer perimeter, and I misunderstood the question to seeking a minimum perimeter, instead of a minimum perimeter for a set with K points.

This new problem is probably NP as suspected, and most similar to the longest path problem. Unfortunately, I lack the ingenuity to provide a worthwhile reduction.

MikeD
This gives you a convex hull algorithm - he's trying (I think) to find the best subset K from the points in N where the hull of K is a minimum. This just generates a hull - but doesn't answer the "real" question, from my reading of it.
Reed Copsey
But that's the thing: He wants to know an algorithm to find WHAT set of points provides the smallest convex hull for the specified number of points.
JAB
Did you by any chance stop reading the question after seeing the words "convex hull"?
IVlad
+1  A: 

One possible optimization: You can ignore any subsets whose convex hull contains points that are not in the subset.

Proof:

If your convex hull contains points that are not in your subset, then remove a point from your subset that is on the hull, and replace it with a point in the interior of the hull. This will yield a hull of equal or smaller perimeter.

mbeckish
How exactly would this work in practice? In order to ignore those subsets you have to compute their convex hulls (or at least find if their convex hulls contain points that aren't in the subset), so you're not actually ignoring them.
IVlad
Also, if you replace a hull point with one that is in the hull's interior, the new hull isn't necessarily convex. So when you regenerate the convex hull it may not include the interior point and you will have a convex hull with less than K points. Consider a pentagonal convex hull with an additional interior point at its center. Replace any vertex with that center point and the resulting polygon will not be convex.
A. Levy
@A. Levy - When you regenerate the convex hull, the newly selected point will need to be either on or inside the convex hull, or else you regenerated the convex hull incorrectly.
mbeckish
@IVlad - The idea is that once you find one convex hull with extra interior points, you use that knowledge to prune some other permutations of points in advance. For example, consider k = 30, and say that a certain subset yields a convex hull with 3 points on the hull, and extra interior points. You can now eliminate all permutations of the 3 points on the hull and the possibly thousands of points outside of the hull, because any such subsets would yield a hull that contains the original hull, and thus should be ignored.
mbeckish
By "You can now eliminate all permutations of the 3 points on the hull and the possibly thousands of points outside of the hull", I mean any subsets that include the 3 points on the original convex hull, plus k-3 other points from the set of points exterior to the convex hull.
mbeckish
@andand: that is not a counterexample; since the subset is the set, the hull contains no point not in the set.
Beta
@Beta: You're right; I misread it.
andand
+2  A: 

It's not exactly pretty solution. In fact, it's quite a pain to implement, but it surely gives polynomial complexity. Although complexity is also big (n^5*k is my rough estimate), someone may find a way to improve it or find here an idea for better solution. Or it may be enough for you: even this complexity is much better than bruteforce.

Note: optimal solution (set S) with hull H includes all points from orignal set inside H. Otherwise, we could throw away one of the border points of H and include that missed point, reducing perimeter.
(update just like 'optimization' mbeckish posted)

Assumption: no two points from the set form a vertical line. It can be achieved easily by rotating whole set of points by some irrational angle around origin of coordinates.

Due to assumption above, any complex hull has one leftmost and one rightmost point. Also, these two points divide the hull into top and bottom parts.

Now, let's take one segment from the top part of this hull and one from the bottom part. Let's call those two segments middle segments and perimeter of the right part of this hull - right perimeter.
Note: those two segments is all we need to know about right part of our convex hull to continue building it to the left. But having just two points instead of 4 is not enough: we could not uphold condition of 'convexness' this way.

It leads to a solution. For each set of points {p0, p1, p2, p3} and number i (i <= k) we store minimal right perimeter that can be achieved if [p0, p1], [p2, p3] are two middle segments and i is the number of points in the right part of this solution (including the ones inside of it, not only on the border).

We go through all points from right to left. For each new point p we check all combinations of points {p0, p1, p2, p3} such that point p can continue this hull to the left (either on the top or on the bottom part). For each such set and size i, we already store optimal perimeter size (see paragraph above).

Note: if you add point p to a right-hull formed by points {p0, p1, p2, p3}, you'll increment set size i at least by 1. But sometimes this number will be > 1: you'll have to include all points in the triangle {p, p0, p2}. They aren't on the hull, but inside it.

Algorithm is over :) In addition, despite scary complexity, you may note that not all segments [p0, p1], [p2, p3] can be middle segments: it should reduce actual computation time substantially.

update This provides only optimal perimeter size, not the set itself. But finding the set is simple: for each 'state' above you store not only perimeter size, but also last point added. Then, you can 'trace' your solution back. It's quite standard trick, I suppose it's not a problem for you, you seem to be good at algorithms :)

update2 This is essentially DP (dynamic programming), only a bit bloated

Nikita Rybak
Like the overall approach - A DP approach seems like the way to go. Also the brute force approach should have complexity C(n,k) (not n^k) *k*log(k) which for some problems with k<<n (or k close to n) may be a better choice.
Grembo
@Nikita Rybak: I'm not sure I completely see what you're describing here, so if I may ask for clarification on a specific point: How does this work if the convex hull with minimum perimiter length is a triangle?
andand
@andand k=3 is the worst way to 'simplify' this algorithm: it would essentially come down to trying all combinations of three points. I'd suggest to get familiar with DP first: it's a really generic technique which can help you with lots of different problems.
Nikita Rybak
@Nikita Rybak Refrering to "rotating whole set of points by some irrational angle" ... for example 2*PI :)
belisarius
@Beta: I wasn't looking to simplify the problem. What I was saying is that I don't see how your algorithm will ever consider triangular convex hulls as a potential solution. If the actual solution turns out to be a triangle, how will your algorithm detect it?
andand
@belisarius ok, you get the idea :) If you want to use radians, it could be 1.
Nikita Rybak
@andand So you're suggesting algorithm have special case which should be condsidered separately? I guess. But it doesn't make it less correct :)
Nikita Rybak
+6  A: 

This can be done in O(kn^3) time and O(kn^2) space (or maybe O(kn^3) if you want the actual points).

This paper: http://www.win.tue.nl/~gwoegi/papers/area-k-gons.pdf

by Eppstein et al, has algorithms to solve this problem for minimum perimeter and other weight functions like area, sum of internal angles etc which follow certain constraints, even though the title says minimum area (See Corollary 5.3 for perimeter).

The basic idea is a dynamic programming approach as follows (read the first few paragraphs of Section 4):

Suppose S is the given set of points and Q is the convex hull of k points with minimum perimeter.

Let p1 be the bottom-most point of Q, p2 and p3 are the next points on the hull in counter-clockwise order.

We can decompose Q into a triangle p1p2p3 and a convex hull of k-1 points Q' (which shares the side p1p3 with triangle p1p2p3).

The main observation is that Q' is the optimal for k-1, in which the bottommost point is p1 and the next point is p3 and all the points of Q' lie on the same side of the line p2->p3.

Thus maintaining a 4d array of optimum polygons for the each quadruple (pi, pj, pk, m) such that

  • the polygon is a convex hull of exactly m points of S.
  • pi is the bottom most point of the polygon.
  • pj is the next vertex in counter-clockwise order,
  • all points of the polygon lie to the left of the line pi -> pj.
  • all points lie on the same side of pj->pk as pi does.

can help us find the optimum polygons for m=k, given the optimum polygons for m <= k-1.

The paper describes exactly how to go about doing that in order to achieve the stated space and time bounds.

Hope that helps.

Moron
The paper references finding minimum perimeter k-gons in O(n log n + k<sup>4</sup>n) which might be of interest if k is much smaller than n.
Matthieu M.
@Matthieu: Good observation!
Moron
It's you again :D how do you manage to find all these papers?
Mgccl
It you again too :D! How do you manage to find such nice questions? ;-)
Moron
@Mgccl. Sorry I didn't really answer your question. I am not really sure how I came upon this. This was late last night and I forget! (Sorry for not answering your question _again_)
Moron
Moron comes through again. Great question, great answer and pseudo-code to boot!
Grembo
@Moron you don't have to apologize for it xD. This was a challenge problem my professor assigned last semester for extra credits, I haven't been able to solve it(This problem ruined my spring break xD), as far as I know, no one in my class solved it(maybe because they are getting A's anyway) He never gave the answer. I emailed him and haven't heard a response yet. So I posted it here.
Mgccl