Handouts:
3/4/09: Convex hulls in 2D
I teach primarily from
slides
Graham Scan: Describe in detail, with example.
Graham scan algorithm: (1) angularly sort (in O(n log n)) about a hull vertex (rightmost among the bottommost),
then (2) do Graham scan (in O(n) time, since each point is pushed or popped from the stack at most once).
This gives a worst-case O(n log n) algorithm.
Analysis: The sorting
step takes O(n log n), but all other phases are only O(n). The total
time is therefore O(n log n).
We note that the sorting could have been done wrt to x (or y, or any direction),
and a similar method of scan works, e.g., to find the upper hull and lower hull.
Lower bound proof: Omega(n log n) from sorting. (Section 3.6)
We showed that you can use a convex hull algorithm to sort n numbers (lift the
n numbers, x_i, to points (x_i,x_i^2) on the parabola y=x^2...),
therefore showing that one cannot hope to do better than O(n log n).
(We are using the fact that Omega(n log n) holds for
sorting.)
We have argued that this is optimal, as a function of n.
If the
running time is written in terms of both the input size n AND the
output size h, we can do O(n log h), and this is best possible, as a function
of n and h.
Melkman's convex hull algorithm: It computes in linear time (O(n)) the
convex hull of a polygonal chain that is SIMPLE (not
self-intersecting). (Equivalently, it computes the convex hull of a
set of points that are given in an order such that linking the points
in that order yields a noncrossing polygonal chain.) The main point
is that SIMPLICITY HELPS: instead of worst-case O(n log n) or O(n log
h), we can get O(n) if we know the points are the vertices of a simple
chain.
Note: A relatively new result (my own work, joint with
Levcopoulos and Lingas) shows that a convex hull
of n points can be found in time O(n log k), where k is the
number of subchains in a partition of the input chain
into the fewest simple subchains. (Thus, if the input points
specify a simple chain, k=1, and it takes time O(n); if
the input chain arbitrarily intersects intself, k is about n,
and the algorithm takes time O(n log n).)
See
Convex hull algorithm applets.