# On computing the convex hull [closed]

I'm given $$n$$ points $$(p_1, p_2, \ldots, p_n)$$, lying on the boundary of a polygon and constituting this polygon (not necessarily convex), whereby those points are given me in clockwise order and I want to compute the convex hull of this polygon, i.e. determine the set of points $$S \subseteq \{p_1, p_2, \ldots, p_n\}$$ s.t. the points in $$S$$ shape the convex hull of the polygon. The tricky part is that my runtime constraint is $$O(n)$$, which is why I'm very stuck on this task. One should output the points of the convex hull in counterclockwise order.

• What do you mean by "compute the convex hull"? In what form do you want the output of your algorithm? May 30 at 9:57
• Google it. You'll quickly find an answer. May 30 at 9:57
• @uniquesolution unfortunately not, the runtime constraint makes it more difficult May 30 at 9:59
• @Klaus I want the subset of the given points that shape the convex hull in form of a list, printed or whatever you prefer (that's not of much importance, rather how the algorithm works) May 30 at 10:00
• It is claimed in this question that the convex hull of a simple polygon is found in linear time by Melkman's algorithm. May 30 at 10:09

One algorithm that does the above is Lee's algorithm, explained in this paper https://link.springer.com/content/pdf/10.1007/BF00993195.pdf

Given an unordered set of points, Graham scan yields their convex hull in O(N log N) time complexity. The limiting factor is the sort phase; everything else is linear in time, as the Wikipedia article explains.

When N is a positive integer with a known maximum (for example, 232-1 when using C uint32_t, or 264-1 when using C uint64_t type), you can use radix sort to do the sort phase in linear time, yielding an implementation of Graham scan with linear time complexity, but with a fixed upper limit for N.

If the points are given in a suitable order, other algorithms can be used to achieve linear time complexity.

Quite a few algorithms assume the points given are the vertices of a polygon in order – meaning that each consecutive pair of points given are connected with an edge in the polygon, with the initial and final points also connected with an edge.

Melkman's Convex Hull Algorithm is probably the best known of these; the Wikipedia Convex hull of a simple polygon article lists a couple more. These assume that the polygon given is simple (does not intersect itself, and has no holes); some also assume the polygon is not degenerate (a line segment) or that consecutive points (polygon vertices) are not collinear.

I would recommend you examine your data properties, to see how you can get under the O(N log N) time complexity boundary (due to sorting); either by (implicitly) limiting N (so you can use radix sort with linear time complexity), or by leveraging data order (avoiding the need to sort altogether).

Finally, note that time complexity is not a measure of computational efficiency, but of how an algorithm scales as the problem set grows. In particular, radix sort algorithms tend to be "slow" in practice, with several O(N log N) being "faster" up to a very large N (last time I checked, on the order of millions to hundreds of millions, depending on exact implementation – computer cache architecture details being a deciding factor!).

• I've already found a solution in $O(n)$ time, your answer doesn't get the point of my question May 30 at 16:42
• @TaChu: No, Lee's algorithm only works on simple polygons, just like Melkman's. Lee's algorithm is also listed on the Wikipedia "Convex hull of a simple polyhon" page I linked to above. Furthermore, the "simple polygon" argument in the question only applies if one assumes the points are given in order, and are not just an unordered set of points on the boundary of the polygon. But thanks for the downvote anyway. May 30 at 22:24
• I can't and wouldn't downvote your post (I have too few reputation). Moreover, I specified in my question that the order is clockwise Jun 1 at 9:27