Lecture # 2

Instructor: Scot Drysdale June 25, 1996

Back to DIMACS Lectures

Discussion continued from day 1

A Line of Support of S contains 1 point in S and has all points in S are in one closed half plane. (The other closed halfplane is empty.) Any point with a line of support through it is on the boundary of the convex hull.

Quick Hull - start with max and min x and y, anything inside the resulting diamond isn't on the hull. Break down into 4 triangle sub problems - one set outside of each edge of the diamond.

For each of these problems, find the outside point farthest away from the segment, and form a triangle by connecting it to the endpoints of the segment. Throw away what is inside the triangle. We have two new, smaller (fewer points) sub problems of the same type - those outside of each of the two new segments. Solve them recursively. (see page 77)

In recursion, sub problems should always be smaller problems than the original. (definition of recursion: see recursion) .

We looked at two naive algorithms based on properties discussed at the end of last class:

Naive Algorithm 1: (improved version suggested in class)

For each triple of points p, q, r S
Throw away every point in S inside the triangle pqr.
Sort all points remaining into a counter-clockwise hull.

Page 97 shows the following notation: (note: the notation in the text is slightly different though equivalent to the notation used in class)

f(n) = O(g(n)); f(n) grows no faster than g(n)
There exist constants C and N such that for all n >N, |f(n)| C * g(n)
if f(n) = 20 n3 + 20,000 n2 + 17n + 6

= 0(n3)

f(n) = W(g(n))
There exists constant C such that |f(x)| C * g(n) infinitely often

Sorting is lower bounded by nlogn; W (nlogn)

f(n) = q(g(n)) if f(n) = O(g(n)) and
f(n) = W (g(n))

lg means log2

Number of triangles is = q (n3)

Testing each point to see if it is inside of a given triangle, there are n-3 points to test. Using left of test, there are 3 tests needed, one for each side. So q(n) time needed to test all points inside of a given triangle.
q(n3) repetitions of a q(n) time test gives q(n4) total time needed.

Naive algorithm 2:
For each pair of points (p,q) see if all points lie to the right of directed line pq. If so report as an edge, else ignore. Number of pairs is q(n2). Number of points to test against the line to see if they lie to the right is n-2, which is q(n). So total time = q (n3)




Read Chapter 3 after this lecture...

Quick Hull - find max and mins, make a diamond and throw out everything in the center. Create 4 sub problems, triangles - 3rd point is farthest away, throw away what is inside the triangle.

Algorithms
Naive 1 triangle testing q(n4) (see Lemma 3.2.1 page 74)

Naive 2 try all pairs see if it forms an edge q(n3) (see 3.2.2 page 74)

Jarvis - "Rope fence" algorithm - find the left most point (in case of tie use the lowest) and tie a rope to it. Walk around and the rope is snagged on the hull points. Find the time in terms of n, the number of points and h, the number of points on the convex hull. (see page 76 Gift wrap, Jarvis used this algorithm in two dimensional space while Chand and Kapupr worked in arbitrary dimensions)

Incremental - start off with any 3 points, take a 4th point, the idea is to find tangents to the first 2 points, throw out what is in the center. Take the next point, if inside -throw it away, if not inside connect it to the two points it is tangent to. You have the tangent if all points are to the right of that line. (formal description on page 99).
This algorithm is simpler if you sort points by x coordinate first. (exercise 3.7.1[3]).
form a triangle out of the first 3 points
for each of the rest of the points
connect to the previous point
find the left and right tangents, eliminate everything between (points and edges).

We then split into groups to analyze the run times for Rope Fence and Incremental algorithms and it was 10:30!

Supplemental Notes -

radians = 180

A lemma is a small theorem. The author arbitrarily determines whether to use the word lemma or theorem. A lemma is often introduced to be used to prove a larger theorem.

Performance of algorithms is usually given by stating the "worst-case" as a function of the size of the input. (Alternatively we can talk about the "best case" or "average case" run time.) The notation used is O(f(n)) for the upper bound and W(f(n)) for the lower bound. When the upper and lower bounds are the same f(n) the notation used is Q(f(n)).


Homework 2


Exercise 3.9 (p. 111)
a) Do part a)
b) Describe a Q(n2) algorithm to compute all the onion layers.


Solution outline:

a) A hull with an interior must have at least three points. Therefore the maximum number of layers is at most ceiling(n/3). This can be achieved by floor(n/3) nested
triangles with any remaining point or two inside of the innermost triangle.

b) If we use Jarvis's rope fence (also called gift wrapping) to compute the outermost layer, remove that layer, and then repeat for the next layer, etc. the total run time will be Q(n2). If the number of hull points on the ith layer is hi, then computing the first layer takes time O(h1n), the second takes O(h2n), etc. Thus the total time required is O((h1+ h2 + ... ) n) = O(n2). (Note that the sum of the hi is n.) Because Jarvis's algorithm is W(n2) when all points are on the hull, this algorithm is Q(n2).
Mailto: dimacs-www@dimacs.rutgers.edu
Last modified: October 3, 1996