planar convex hulls (ii) - bowdoin collegethe problem: given a set p of points in 2d, describe an...
TRANSCRIPT
![Page 1: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/1.jpg)
Planar convex hulls (II)
Computational Geometry [csci 3250] Laura Toma
Bowdoin College
![Page 2: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/2.jpg)
Convex Hull
The problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull
output: list of points on the CH (in boundary order)
![Page 3: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/3.jpg)
Convexity
A polygon P is convex if for any p, q in P, the segment pq lies entirely in P.
convex non-convex
![Page 4: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/4.jpg)
Properties of CH
• All edges of CH are extreme and all extreme edges of P are on the CH • All points of CH are extreme and all extreme points of P are on the CH • All internal angles are < 180 • Walking counterclockwise—> left turns • Points on CH are sorted in radial order wrt a point inside
![Page 5: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/5.jpg)
Outline
• Last time: • Brute force • Gift wrapping • Quickhull • Graham scan
• Today • Andrew’s monotone chain algorithm • Exercises • Lower bound • More algorithms
• Incremental CH • Divide-and-conquer CH
![Page 6: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/6.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Alternative to Graham’s scan • Idea: Find upper hull and lower hulls separately
![Page 7: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/7.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Alternative to Graham’s scan • Idea: Find upper hull and lower hulls separately
ab
![Page 8: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/8.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Alternative to Graham’s scan • Idea: Find upper hull and lower hulls separately
ab
P1
P2
![Page 9: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/9.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Alternative to Graham’s scan • Idea: Find upper hull and lower hulls separately
ab
P1
P2
![Page 10: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/10.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Alternative to Graham’s scan • Idea: Find upper hull and lower hulls separately
ab
P1
P2
![Page 11: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/11.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 12: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/12.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 13: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/13.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 14: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/14.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 15: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/15.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 16: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/16.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 17: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/17.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 18: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/18.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 19: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/19.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 20: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/20.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 21: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/21.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 22: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/22.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 23: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/23.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 24: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/24.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 25: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/25.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
g
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 26: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/26.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
g
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 27: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/27.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
g
h
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 28: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/28.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
g
h
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
![Page 29: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/29.jpg)
Andrew’s Monotone Chain Algorithm (1979)
a
b
c
d
e
f
g
h
• Goal: find the CH of P1 • Idea: Traverse points in (x,y) order (i.e. lexicographically)
and so on..
![Page 30: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/30.jpg)
Andrew’s Monotone Chain Algorithm (1979)
• Alternative to Graham’s scan • Idea: Traverse points in (x,y) lexicographic order (instead of radial order) • Runs in sort + scan • Sorting lexicographically is faster than sorting radially
![Page 31: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/31.jpg)
![Page 32: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/32.jpg)
Convex hull: summary
Can we do better?
Naive O(n3)
Gift wrapping O(nh) 1970
Graham scan O(n lg n) 1972
Quickhull O(n2) 1977
![Page 33: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/33.jpg)
Lower bound
![Page 34: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/34.jpg)
What is a lower bound?
• Given an algorithm A, its worst-case running time is the largest running time on any input of size n
max |P|=n {T(n) | T(n) is the running time of algorithm A on input P}
• A lower bound for CH: • What is the worst-case running time of the best possible CH algorithm? • Consider all possible CH algorithms, and take the overall smallest worst-
case running time
min A max |P|=n {T(n) | T(n) is the running time of algorithm A on input P}
![Page 35: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/35.jpg)
Lower bounds
Lower bounds depend on the machine model.
Standard model: decision tree, or comparison model
Sorting lower bound: • Any sorting algorithm that uses only comparisons must take at least
Omega( n lg n) in the worst case.
![Page 36: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/36.jpg)
• Assume we can show that: we can sort by an instance of CH
sort (input: array A) • create a set P of points from A • find CH(P) • form the CH infer sorted order of A
• Analysis: • Assuming that the first and last step are O(n), then • sort = find convex hull + O(n)
• If we can find such a reduction, this proves an Omega(n lg n) lower bound for CH • Why?
Lower bounds by reduction
sorting reduces to CH
![Page 37: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/37.jpg)
Sorting reduces to CH
• Assume we are given a set of of numbers x1, x2, …xn to sort.
![Page 38: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/38.jpg)
• Assume we are given a set of of numbers x1, x2, …xn to sort. • Suppose we have an algorithm that constructs the CH of a set of n
points in worst-case T(n) time.
Sorting reduces to CH
![Page 39: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/39.jpg)
• Assume we are given a set of of numbers x1, x2, …xn to sort. • Suppose we have an algorithm that constructs the CH of a set of n
points in worst-case T(n) time. • Our goal is to argue that there exists some instance of a convex hull
problem that sorts our numbers.
Sorting reduces to CH
![Page 40: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/40.jpg)
• Input: set of points x1, x2, …xn • Form a set of 2D points (xi, xi2).
x2
Sorting reduces to CH
![Page 41: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/41.jpg)
Sorting reduces to CH
• Input: set of points x1, x2, …xn • Form a set of 2D points (xi, xi2).
![Page 42: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/42.jpg)
• Input: set of points x1, x2, …xn • Form a set of 2D points (xi, xi2). • Run the CH algorithm to construct their convex hull.
Sorting reduces to CH
![Page 43: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/43.jpg)
• They fall on a parabola, so every point is on the hull
Sorting reduces to CH
![Page 44: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/44.jpg)
• Find the lowest point on the hull, and walk from in ccw order.
Sorting reduces to CH
![Page 45: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/45.jpg)
• Find the lowest point on the hull, and walk from in ccw order. • This is sorted order!
Sorting reduces to CH
![Page 46: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/46.jpg)
• Input: set of points x1, x2, …xn • Form a set of 2D points (xi, xi2). • Run the CH algorithm to construct their convex hull. • Find the lowest point on the hull, and walk from in ccw order. This is sorted
order! • If we could find the CH faster than n lg n, then we could sort faster than n lg n!
Impossible!
Sorting reduces to CH
![Page 47: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/47.jpg)
• What we actually proved is that • Any CH algorithm that produces the boundary in order must take
Omega (n lg n) in the worst case.
• If we did not want the boundary in order, can the CH be constructed faster? • It was an open problem for a while • Finally, it was established that a convex hull algorithm, even if it does
not produce the boundary in order, still needs Omega (n lg n)
Sorting reduces to CH
![Page 48: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/48.jpg)
• Yes, Graham scan is the ultimate CH algorithm but… • not output sensitive • does not extend to 3D
• The (re)search continues
![Page 49: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/49.jpg)
An incremental algorithm for CH
![Page 50: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/50.jpg)
Incremental algorithms
• Goal: solve problem P • Idea: traverse points one at a time and solve the problem for points seen so far
• Incremental Algorithm • initialize solution S = initial solution • for i=1 to n
• //S represents solution of p1…….pi-1 • add pi to S and update S to represent solution of p1…..pi-1pi
![Page 51: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/51.jpg)
Incremental algo for CH
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 52: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/52.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 53: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/53.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 54: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/54.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 55: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/55.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 56: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/56.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 57: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/57.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 58: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/58.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 59: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/59.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 60: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/60.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 61: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/61.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 62: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/62.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 63: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/63.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 64: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/64.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 65: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/65.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 66: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/66.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 67: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/67.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 68: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/68.jpg)
Incremental algo for CH
p1
p2
p3
p4
p6p5
p7
p8
p15
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 69: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/69.jpg)
Incremental algo for CH
• The basic operation is adding a point to a convex polygon • How many cases? • How to handle each case?
• Class work: Simulate the approach on a set of points and try to answer these questions.
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 70: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/70.jpg)
Incremental algo for CH
• The basic operation is adding a point to a convex polygon • CASE 1: p is in polygon • CASE 2: p outside polygon
• CH = {} • for i=1 to n
• //CH represents the CH of p1..pi-1 • add pi to CH and update CH to represent the CH of p1..pi
![Page 71: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/71.jpg)
Incremental algo for CH
• Issues to solve • What’s a good representation for a polygon? • We need a point-in-polygon test ? • How to handle CASE 2 ?
![Page 72: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/72.jpg)
Representing a polygon
A polygon is represented as a list of vertices in boundary order.
(the convention is counter-clockwise order)
typedef struct _polygon{
int k; //number of vertices
Point* vertices; //the vertices, ccw in boundary order
} Polygon;
or
Vector<Point> //note: the vertices, ccw in boundary order
![Page 73: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/73.jpg)
Point in convex polygon
//return TRUE iff p on the boundary or inside H; H is convex a polygon
bool point_in_polygon(point p, polygon H)
p
What has to be true in order for p to be inside?
![Page 74: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/74.jpg)
Point in convex polygon
//return TRUE iff p on the boundary or inside H; H is convex a polygon
bool point_in_polygon(point p, polygon H)
//p is inside if and only if it is on or to the left of all edges, oriented ccw
//note: this is NOT true for a non-convex polygon — can you show a
//counter-example?
Analysis: • O(k) where k is the size of the polygon
p
![Page 75: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/75.jpg)
Case 2:
p
pi
pj
We want to find pi and pj
IDEAS?
![Page 76: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/76.jpg)
Case 2:
Hint: Check the orientation of p wrt the edges of the polygon.
p
pi
pj
We want to find pi and pj
![Page 77: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/77.jpg)
Case 2:
p
pj
pi
R
R
RL
L
LL
We want to find pi and pj
Hint: Check the orientation of p wrt the edges of the polygon.
![Page 78: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/78.jpg)
Case 2:
Hint: Check the orientation of p wrt the edges of the polygon.
What do you notice? How can we use this to find the tangent points? Sketch an algorithm. How long does it take?
p
pi
pj
We want to find pi and pj
![Page 79: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/79.jpg)
Finding tangent points
Input: point p outside H
polygon H = [p0, p1,…, pk-1] convex
• for i=0 to k-1 do • prev = ((i == 0)? k-1: i-1); • next = (i==k-1)? 0; k+1); • if XOR (p is left-or-on (pprev, pi), p is left-or-on(pi, pnext)) • then pi is a tangent point
pi
R
R
RL
L
LL
pj
After finding pi and pj, how would you update H?
![Page 80: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/80.jpg)
Back to an incremental algorithm for CH
![Page 81: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/81.jpg)
• H = [p1, p2, p3] • for i=4 to n do
• //add pi to H • if point_in_polygon(p, H)
• //do nothing • else
• find pi the tangent point where orientation changes from L to R • find pj the tangent point where orientation changes from R to L
//note: pi not necessarily before pj in the vertex array of H • cut out the part from pi to pj in H (note: view H as wrapping around)
and replace it with vertex p
Incremental algo for CH
![Page 82: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/82.jpg)
• H = [p1, p2, p3] • for i=4 to n do
• //add pi to H • if point_in_polygon(p, H)
• //do nothing • else
• find pi the tangent point where orientation changes from L to R • find pj the tangent point where orientation changes from R to L
//note: pi not necessarily before pj in the vertex array of H • cut out the part from pi to pj in H (note: view H as wrapping around)
and replace it with vertex p
Incremental algo for CH
Simulate the algorithm on a couple of examples. Think how pi could come before pj in H or the other way around.
![Page 83: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/83.jpg)
• H = [p1, p2, p3] • for i=4 to n do
• //add pi to H • if point_in_polygon(p, H)
• //do nothing • else
• find pi the tangent point where orientation changes from L to R • find pj the tangent point where orientation changes from R to L
//note: pi not necessarily before pj in the vertex array of H • cut out the part from pi to pj in H (note: view H as wrapping around)
and replace it with vertex p
Incremental algo for CH
Analysis:
![Page 84: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/84.jpg)
• H = [p1, p2, p3] • for i=4 to n do
• //add pi to H • if point_in_polygon(p, H)
• //do nothing • else
• find pi the tangent point where orientation changes from L to R • find pj the tangent point where orientation changes from R to L
//note: pi not necessarily before pj in the vertex array of H • cut out the part from pi to pj in H (note: view H as wrapping around)
and replace it with vertex p
Incremental algo for CH
Analysis: SUMi O(i) = O(n2)
O(i)
O(i)
![Page 85: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/85.jpg)
• The “straightforward” incremental algorithm is O(n2) • Improvement:
• pre-sort the points by their x-coordinates and add them in this order
What does this give us?
• It was shown that O(n lg n) incremental algorithm is possible. • avoid re-computing all directions every time • replace the search for tangent points with some sort of binary search
Incremental algo for CH
R
R
RL
L
L
L
![Page 86: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/86.jpg)
A divide-and-conquer algorithm for CH
![Page 87: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/87.jpg)
Divide-and-conquer
DC(input P)if P is small, solve and return else
//dividedivide input P into two halves, P1 and P2//recurse result1 = DC(P1) result2 = DC(P2) //merge do_something_to_figure_out_result_for_P return result
Analysis: T(n) = 2T(n/2) + O(merge phase)
• if merge phase is O(n): T(n) = 2T(n/2) + O(n) => O( n lg n)
![Page 88: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/88.jpg)
CH via divide-and-conquer
![Page 89: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/89.jpg)
• find vertical line that splits P in half
CH via divide-and-conquer
![Page 90: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/90.jpg)
• find vertical line that splits P in half • let P1, P2 = set of points to the left/right of line
P1 P2
CH via divide-and-conquer
![Page 91: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/91.jpg)
• find vertical line that splits P in half • let P1, P2 = set of points to the left/right of line • recursively find CH(P1)
P1 P2
CH via divide-and-conquer
![Page 92: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/92.jpg)
• find vertical line that splits P in half • let P1, P2 = set of points to the left/right of line • recursively find CH(P1) • recursively find CH P2
P1 P2
CH via divide-and-conquer
![Page 93: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/93.jpg)
• find vertical line that splits P in half • let P1, P2 = set of points to the left/right of line • recursively find CH(P1) • recursively find CH P2 //now get somehow CH(P)
P1 P2
CH via divide-and-conquer
![Page 94: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/94.jpg)
• find vertical line that splits P in half • let P1, P2 = set of points to the left/right of line • recursively find CH(P1) • recursively find CH P2 //now get somehow CH(P)
P1 P2
CH via divide-and-conquer
![Page 95: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/95.jpg)
P1 P2
Merging two hulls..in linear time
• Need to find the two tangents
![Page 96: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/96.jpg)
P1 P2
Merging two hulls..in linear time
• Here it looks like the upper tangent is between the top points in P1 and P2 • Is that always true?
![Page 97: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/97.jpg)
Not necessarily…
![Page 98: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/98.jpg)
The top-most point overall is on the CH, but not necessarily on the upper tangent
![Page 99: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/99.jpg)
Merging two hulls..in linear time
• Naive algorithm: try all segments (a,b) with a in H1 and b in H2
Too slow. => O(n2) merge, O(n2 lg n) CH algorithm
H1 H2
![Page 100: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/100.jpg)
Finding the lower tangent
• Claim: All points in H1 and H2 are to the left of ab
a
b
H1 H2
![Page 101: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/101.jpg)
Finding the lower tangent
• Claim: Points a,b are on the lower hulls of H1 and H2, respectively.
a
b
H1 H2
![Page 102: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/102.jpg)
• Idea: • start with a = rightmost point in H1, b = leftmost point in H2 • lower a until all H1 is left of ab • lower b until all H2 is left of ab • repeat
a b
H1 H2
Finding the lower tangent
![Page 103: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/103.jpg)
a
b
H1 H2
• Idea: • start with a = rightmost point in H1, b = leftmost point in H2 • lower a until all H1 is left of ab • lower b until all H2 is left of ab • repeat
Finding the lower tangent
![Page 104: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/104.jpg)
a
b
H1 H2
• Idea: • start with a = rightmost point in H1, b = leftmost point in H2 • lower a until all H1 is left of ab • lower b until all H2 is left of ab • repeat
Finding the lower tangent
![Page 105: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/105.jpg)
b
a
H1 H2
• Idea: • start with a = rightmost point in H1, b = leftmost point in H2 • lower a until all H1 is left of ab • lower b until all H2 is left of ab • repeat
Finding the lower tangent
![Page 106: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/106.jpg)
b
a
H1 H2
• Idea: • start with a = rightmost point in H1, b = leftmost point in H2 • lower a until all H1 is left of ab • lower b until all H2 is left of ab • repeat
Finding the lower tangent
![Page 107: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/107.jpg)
b
a
H1 H2
• Idea: • start with a = rightmost point in H1, b = leftmost point in H2 • lower a until all H1 is left of ab • lower b until all H2 is left of ab • repeat
Finding the lower tangent
![Page 108: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/108.jpg)
b
a
H1 H2
Claim: At any point during the algorithm, segment ab cannot intersect the interior of the polygons ==> a cannot move into the upper hull of P1, b cannot move into the upper hull of P2
==> The algorithm terminates
==> O(n)
(why) does this work?
![Page 109: Planar convex hulls (II) - Bowdoin CollegeThe problem: Given a set P of points in 2D, describe an algorithm to compute their convex hull output: list of points on the CH (in boundary](https://reader034.vdocument.in/reader034/viewer/2022052004/6017e6b24b13174f2e663a1f/html5/thumbnails/109.jpg)
• Yet another illustration of divide-and-conquer paradigm • Runs in O(n lg n) • Extends to O( n lg h) • Extends nicely to 3D
CH via divide-and-conquer