Title: Convex hull
1Convex hull
smallest convex set containing all the points
2Convex hull
smallest convex set containing all the points
3Convex hull
smallest convex set containing all the points
3
2
start 1
1.next 2 3.prev 2.next 3 4.prev 3.next
4 1.prev 4.next 1 2.prev
4
1
representation circular doubly-linked list of
points on the boundary of the convex hull
4Jarvis march
(assume no 3 points colinear)
s
find the left-most point
5Jarvis march
(assume no 3 points colinear)
s
find the point that appears most to the right
looking from s
6Jarvis march
(assume no 3 points colinear)
s
find the point that appears most to the right
looking from p
p
7Jarvis march
(assume no 3 points colinear)
8Jarvis march
(assume no 3 points colinear)
9Jarvis march
(assume no 3 points colinear)
s ? point with smallest x-coord p ? s repeat
PRINT(p) q ? point other than p for i from
1 to n do if i ? p and point i to the
right of line (p,q) then q ? i p?
q until p s
10Jarvis march
(assume no 3 points colinear)
Running time O(n.h)
11Graham scan
(assume no 3 points colinear)
O(n log n) homework
start with a simple polygon containing all the
points fix it in time O(n)
12Graham scan
(assume no 3 points colinear)
13Graham scan
(assume no 3 points colinear)
14Graham scan
(assume no 3 points colinear)
15Graham scan
(assume no 3 points colinear)
16Graham scan
(assume no 3 points colinear)
17Graham scan
(assume no 3 points colinear)
18Graham scan
(assume no 3 points colinear)
A ? start B ? next(A) C ? next(B) repeat 2n
times if C is to the right of AB then
A.next ? C C.prev ? A B ? A A ?
prev(A) else A ? B B ? C
C ? next(C)
19Closest pair of points
20Closest pair of points
21Closest pair of points
2T(n/2)
? ? min(left,right)
22Closest pair of points
?
?
2T(n/2)
? ? min(left,right)
23Closest pair of points
?
?
?
2T(n/2)
? ? min(left,right)
?
24Closest pair of points
pre-processing
X ? sort the points by x-coordinate Y ? sort the
points by y-coordinate
Closest-pair(S) if S1 then return ? if
S2 then return the distance of the pair
split S into S1 and S2 by the X-coord ?1?
Closest-pair(S1), ?2? Closest-pair(S2) ? ?
min(?1,?2) for points x in according to Y
check 12 points around x, update ? if a
closer pair found
25Smallest enclosing disc
26Smallest enclosing disc
27Smallest enclosing disc
Claim 1
The smallest enclosing disc is unique.
28Smallest enclosing disc
Claim 1
The smallest enclosing disc is unique.
29Smallest enclosing disc
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
30Smallest enclosing disc
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
SED-with-point(S,y) pick a random point x? S
(c,r) ? SED-with-point(S-x,y) if x?Disc(c,r)
then return (c,r) else return
SED-with-2-points(S,y,x)
31Smallest enclosing disc
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
SED-with-point(S,y) pick a random point x? S
(c,r) ? SED-with-point(S-x,y) if x?Disc(c,r)
then return (c,r) else return
SED-with-2-points(S,y,x)
SED-with-2-point(S,y,z) pick a random point x?
S (c,r) ? SED-with-2-points(S-x,y,z) if
x?Disc(c,r) then return (c,r) else return
circle given by x,y,z
32Running time ?
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
SED-with-point(S,y) pick a random point x? S
(c,r) ? SED-with-point(S-x,y) if x?Disc(c,r)
then return (c,r) else return
SED-with-2-points(S,y,x)
SED-with-2-point(S,y,z) pick a random point x?
S (c,r) ? SED-with-2-points(S-x,y,z) if
x?Disc(c,r) then return (c,r) else return
circle given by x,y,z
33Running time ?
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
SED-with-point(S,y) pick a random point x? S
(c,r) ? SED-with-point(S-x,y) if x?Disc(c,r)
then return (c,r) else return
SED-with-2-points(S,y,x)
O(n)
SED-with-2-point(S,y,z) pick a random point x?
S (c,r) ? SED-with-2-points(S-x,y,z) if
x?Disc(c,r) then return (c,r) else return
circle given by x,y,z
34Running time ?
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
O(n)
SED-with-point(S,y) pick a random point x? S
(c,r) ? SED-with-point(S-x,y) if x?Disc(c,r)
then return (c,r) else return
SED-with-2-points(S,y,x)
2
T(n) T(n-1)
SED-with-2-points
n
T(n) O(n)
35Running time ?
SED(S) pick a random point x? S (c,r) ?
SED(S-x) if x?Disc(c,r) then return (c,r)
else return SED-with-point(S,x)
O(n)
2
T(n) T(n-1)
SED-with-point
n
T(n) O(n)
36Smallest enclosing disc
md(I,B) smallest enclosing disc with B on
the boundary and I inside
Claim 2
if x is inside md(I,B) then md(I ? x,B)
md(I,B)
37Smallest enclosing disc
md(I,B) smallest enclosing disc with B on
the boundary and I inside
Claim 3
if x is outside of md(I,B) then md(I ?
x,B) md(I,B ? x)
38Smallest enclosing disc
md(I,B) smallest enclosing disc with B on
the boundary and I inside
Claim 3
if x is outside of md(I,B) then md(I ?
x,B) md(I,B ? x)
x
md(I,B)
md(l ? x,B)
39Smallest enclosing disc
md(I,B) smallest enclosing disc with B on
the boundary and I inside
Claim 3
if x is outside of md(I,B) then md(I ? x,B)
md(I,B ? x)
Claim 2
if x is inside md(I,B) then md(I ? x,B)
md(I,B)
Claim 1
md(I,B) is unique