COSC 6114 - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

COSC 6114

Description:

aff(S) = the set of all affine ... (flat = any set affine equivalent to k , for some k d. ... { gift-wrapping method, generalizes to higher dimensions} ... – PowerPoint PPT presentation

Number of Views:295
Avg rating:3.0/5.0
Slides: 52
Provided by: cseY2
Category:

less

Transcript and Presenter's Notes

Title: COSC 6114


1
COSC 6114
Prof. Andy Mirzaian
2D Convex Hull
2
TOPICS
  • Affine Hull
  • Convex Hull
  • 2D Convex Hull
  • Static Algorithms
  • Applications
  • Dynamic Algorithms

3
Affine HULL
Given S ? ?d (d 1,2,3, )
Affine-Hull of S aff(S) the set of all
affine combinations of points in S the
smallest flat that contains S (flat
any set affine equivalent to ?k , for some k ?
d.)
In general dimension k of aff(p1, p2 , ,
pn) rank of matrix p2-p1, p3-p1 ,
, pn-p1.
4
CONVEX HULL
Given S ? ?d (d 1,2,3, )
Convex-Hull of S CH(S) the set of all convex
combinations of points in S the smallest
convex set that contains S the
intersection of all convex sets that contain S
5
The Convex Hull Problem
Given a set Sp1,p2, , pn of n points in ?d ,
compute CH(S).
In general, CH(S) will be a convex polytope whose
vertices are a subset of S, called extreme
points of S.
6
2D Convex Hull Early development
Caratheodorys Theorem p is NOT an extreme
point ? p is a convex-combination of up to 3
(d1) other points.
O(n4) is too slow.
7
2D CH An O(n3) time algorithm
  • Algorithm CH(P)
  • E ? ? ( edge-list of CH(P) )
  • for all ordered pairs (p,q) ? P?P, p ? q do
  • supporting ? true
  • for all points r ? P-p,q do
  • if r is on the right side
    of pq then supporting ? false
  • if supporting then add directed edge
    pq to E
  • From the (un-ordered) edge-list E, construct the
    list of vertices of CH(P) in CCW order in
    O(n) time. (How?)
  • end

q
O(n3) still too slow!
p
8
QUICK HULL (similar to QuickSort - see AAW)
S
9
QUICK HULL
S2
B
rightmost
A
leftmost
S1
A B are extreme points (admit vertical
supporting lines) S1 ? points to the right of
AB S2 ? points to the right of BA Initialize
CH to AB followed by BA. (uninflated
baloon) Call FindHull (S1,A,B) and
FindHull(S2, B,A)
10
  • FindHull(P,A,B)
  • If P is empty, then return.
  • Find (extreme) point C?P orthogonally farthest
    from AB.
  • CH update replace AB with AC followed by CB.
    (inflate baloon)
  • Partition P-C into Q0, Q1, Q2 as shown.
  • Discard Q0 inside triangle ABC (by
    Caratheodory).
  • Recursively call FindHull(Q1,A,C) and
    FindHull(Q2,C,B).

B
max
Q2
Q0
A
supporting line at C (C is extreme point)
Q1
C
11
QuickHull animation
12
T(n) Time Complexity of FindHull(P,A,B),
where nP
- Find C, Q0, Q1, Q2 O(n) time -
FindHull(Q1,A,C) T(q) time. ( Q1
q ) - FindHull(Q2,C,B) T(n-1-q) time.
( Q2 ? n-1-q )
Worst Case T(n) max T(q) T(n-1-q)
O(n) 0 ? q ? n-1 T(0) T(n-1)
O(n) O(n2) Average
Case On many realistic point distributions
AvgT(n) O(n) or close to it.
13
Algorithm Jarvis March 1973
gift-wrapping method, generalizes to higher
dimensions Step 1 Let p1 be the point with
minimum y-coordinate (lex.) Step 2 Anchor ray at
current point and rotate to next anchor point.
Repeat.
p4
p3
p5
p2
Ray
p1
Output-sensitive O(nh) time. n input
points, h hull vertices (output size) (3 ?
h ? n if n ? 3 and not all points
collinear) Worst-case O(n2) time.
14
Algorithm Graham-Scan (p1 .. pn) 1972
Step 1 Polar-Sort p1 .. pn Find a
lexicographically min point among pi (e.g.,
leftmost-lowest point) and swap with p1. Sort p2
.. pn by their polar angle of rays p1 pi ,
i2..n. (Use ?test to simulate comparisons in
the sorting.)
O(n log n)
p4
p6
p3
p7
p5
p2
p8
p1
Step 2 Stack S ? (p2 , p1) ( p1 at the
bottom ) for i ? 3 .. n do while not
CW(pi, Top(S), 2ndTop(S)) do POP(S)
PUSH(pi,S) end-for
O(n)
Step 3 return S ( vertices of CH(p1 .. pn )
in CCW order )
O(n)
15
Graham-Scan a snapshot of step 2
pi
p7 p6 p5 p4 p3 p2 p1
pi
p4
p5
p6
p3
p7
p2
Stack S
p1
16
? (n log n) Lower Bound for 2D Convex Hull
Problem
Reduction from Sorting (using the Lifting
Method)
Sort X (x1, x2, , xn ) (n given real
numbers on the x-axis)
?
?(n log n) O(n) T(n) O(n) ? T(n) ?(n
log n).
17
  • Algorithm Divide--Conquer 2D Convex-Hull
  • x-sort the given points p1, p2, , pn
    (lexicographically).
  • Call CH(p1, p2, , pn ).

T(n) 2 T(n/2) O(n) O( n log n).
18
Divide--Conquer algorithm
upper bridge
CH(R)
CH(L)
lower bridge
n/2
n/2
x-median
19
Other 2D Convex-Hull Algorithms (Lecture Notes 1
2)
Melkman 1987 Convex-Hull of a simple polygon
in linear time.
Kirkpatrick-Seidel 1986 2D convex-hull of n
points in O(n log h) time. n input size h
output size (i.e., convex hull vertices) 3
? h ? n (if n ? 3 and not all points
are collinear) This is a good example of a
prune--search algorithm.
20
Melkmans Linear-Time algorithm for CH of Simple
Polygon
Input Simple polygon P ( p1 , p2 , , pn
) Output CH(P) Time O(n) Method
Incrementally maintain CH(p1 , p2 , , pi ) in
a circular deque D(vt,vt-1,,vb1,vb) (top
vt vb bottom)
21
(No Transcript)
22
Kirkpatrick-Seidels O(n log h) time 2D CH
algorithm
23
How to find Upper-Hull of P P L?R, P n,
L ? R ? n/2, upper-bridge pq L ? L, R ?
R (points under the bridge pq ignored) h
upper-hull vertices of P h1 upper-hull
vertices of L h2 upper-hull vertices of
R FACT h h1 h2
q
upper-bridge
p
divide--conquer wastescomputation on points in
thisarea
R
L
R
L
xmed
24
  • Algorithm Upper-Hull (P)
  • if P ? 2 then return the obvious
    answer.
  • xmed ? median x-coordinates of points in P.
  • Partition P into L R of size n/2 each
    around xmed.
  • Find upper-bridge pq of L R, p?L, q?R.
  • L ? l?L xl ? xp
  • R ? r?R xr ? xq
  • LUH ? Upper-Hull (L)
  • RUH ? Upper-Hull (R)
  • return ( LUH , pq , RUH ) ( upper-hull
    edge sequence )

T(n,h)
O(1)
O(n)
O(?)
O(n)
T(n/2,h1)
Recursive calls
T(n/2,h2)
O(n)
25
Key idea compute upper-bridge of L R in O(n)
time (next slides). Define T(n,h) time
complexity of Upper-Hull(P) where n P
and h upper-hull vertices.
THEOREM T(n,h) O( n log h ).
Proof Algorithm gives the recurrence T(n,h) ?
cn max T(n/2 , h1) T(n/2,h2) h1h2h
if h gt 2 T(n,h) ? cn if h ? 2. Induction
hypothesis on h T(n,h) ? c n log 2h, ?h ?
1. Basis (h1,2) T(n,h) ? cn ? cn log
2h. Induction Step (hgt2) T(n,h) ? cn max
c(n/2) log (2h1) c(n/2) log (2h2) h1h2h
cn max c(n/2) log (2h12h2)
2h12h22h cn c(n/2) log
(hh) cn log 2h

QED
26
How to find the upper-bridge of L R in O(n)
time?
This is a 2-variable Linear Program (? , ?).
? slope and ? y-intercept of the
upper-bridge.
27
  • Prune--Search on ?
  • Partition L?R into n/2 arbitrary pairs (r,s), xr
    ? xs
  • ? ? median slope of these n/2 pair slopes(rs)
  • In cases 1 2 we can PRUNE ? n/4 points
  • Case 1 slope(rs) ? ? (holds for ? n/4
    pairs (r,s)) ? slope(rs) gt ? ?
    upper-bridge cannot pass through r. Prune r.
  • Case 2 slope(rs) ? ? (holds for ? n/4 pairs
    (r,s)) ? slope(rs) lt ? ? upper-bridge
    cannot pass through s. Prune s.
  • Case 3 slope(pq) ?. We have found the
    upper-bridge.

s
?
r
?
s
r
?
?
28
  • Prune--Seach Bridge Finding
  • Each prune--search iteration takes linear time
    on the points not yet pruned.
  • It eliminates at least a quarter of the points
    (or finds the optimum slope).
  • If we start with n points, first iteration
    eliminates at least n/4 points.
  • So, at most 3n/4 points remain. Then we iterate
    on the prune--search.
  • Total bridge-finding time
  • O( n (¾) n (¾)2 n (¾)3 n )
    O(n).

CONCLUSION Upper-Bridge (and Lower-Bridge)
finding takes O(n) time. Kirkpatrick-Seidels CH
algorithm takes O(n log h) time.
29
Higher Dimensional Convex Hull
  • Convex hull of n points in 3D can also be
    computed in O(n log n) time, e.g., by the
    divide--conquer method.
  • In general, the convex hull of n points in dgt1
    dimensions can be computed in O( n log n
    n?d/2? ) time.These will be discussed later in
    the course.

30
Some Applications of Convex Hull
  • Diameter ? farthest pair
  • Linear separability
  • Convex Layers
  • Other related problems Smallest enclosing
    circle O(n) time by Megiddo-Dyers
    prune--search technique

31
The Farthest Pair among n points
Given a set S p1, p2, , pn on the
plane, Find the farthest pair, i.e., a pair
(pi,pj) in S such that d(pi,pj) ? d(pt,pk)
?pt,pk ?S. Euclidean distance d(pi,pj) ((xi
xj)2 (yi yj)2 )1/2
32
Algorithm DIAMETER (p1, p2, , pn ) Step 1
P ? CH(p1, p2, , pn )
O(n log n) Step 2
Compute diameter of P by the rotating calipers
method. O(n)
Definition Antipodal Pair (p,q) is an antipodal
pair if there are a pair of parallel supporting
lines of CH(S) Through p and q that sandwich
CH(S) in between. FACT The farthest pair is
one of the antipodal pairs.
33
CLAIM There are ? 2n antipodal pairs they can
all be found in O(n) time.
THEOREM Farthest pair among n points in the
plane can be found in O(n log n) time.
34
Linear Separability
B
A
A B are linearly separable ? CH(A) CH(B)
have disjoint interiors O(n log n)
time. Fastest result O(n) time by prune--search
Exercise
35
Dynamic Convex Hull
36
Dynamic Convex Hull Problem
  • Maintain (the convex hull of) a finite set S ? ?d
    (d2,) under the following operations
  • Insert a given point p into S.
  • Delete a specified point p from S.
  • Query is a given point q inside CH(S)?
  • Report CH(S).

37
Semi-Dynamic 2D CH Insertion only
  • F. Preparata 1979, An optimal real time
    Algorithm for planar convex hulls, Comm. ACM
    22(7)402-405.
  • Insertion time O(log n)
  • Query time O(log n)
  • Memory space O(n)

38
Semi-Dynamic 2D CH Deletion only
  • B. Chazelle 1985, On the convex layers of
    a planar set,
  • IEEE Trans. Info. Theory IT-31(4)509-517.
  • J. Hershberger, S. Suri 1992, Applications
    of a semi-dynamic convex hull algorithm, BIT
    32(2)249-267.
  • Deletion O(log n) amortized time.
  • Memory space O(n)

39
Dynamic 2D CH
  • PrS85 Preparata-Shamos (book) Section 3.3.7
  • M.H. Overmars, J. van Leeuwen 1981,
    Maintenance of configurations in the plane,
    JCSS 23166-204.
  • Maintain both Upper and Lower Hull.
  • Insert O(log2 n) time
  • Delete O(log2 n) time
  • Query O(log n) time
  • CH Report O(h) time.
  • Space O(n)

delete
pointsresurface
  • G. Brodal, R. Jacob 2002, Dynamic planar
    convex hulls IEEE FOCS 2002. Improves
    Insert Delete to O(log n) amortized time.

40
Overmars - van Leeuwen
  • Maintain both U-hull and L-hull separately.

U-hull
41
Overmars - van Leeuwen
  • U-hull 2-level dynamic data structure.

q
x(v), J(v), Q(v)
v
p
bridge
U21
U22
U11
U12
U12
U21
U1
U2
U(v) (U11 , pq , U22) upper-hull of
descendents of v.J(v) index of p in
U(v)Q(v) Secondary structure at v.
Portion of U(v) that does not appear
in parent of v.
x(v)
42
Example
7,3,(11,4,1,5,12)
10,1,(2)
9,2,(7)
1,1,?
8,1,?
4,2,(3,9)
data structure
2,1,(10)
11,1,?
3,1,?
5,1,(8)
6,1,(6)
11
4
3
9
1
7
2
10
5
8
12
6
1
5
hull tree
2
4
7
12
8
3
6
10
9
11
43
Example Insert point 13
7,3,(11,4,1,13,12)
13,2,(2)
9,2,(7)
1,1,?
8,1,?
4,2,(3,9)
data structure
2,1,?
10,1,(10)
11,1,?
3,1,?
5,1,(8)
6,1,(6)
11
4
3
9
1
7
2
10
5
8
12
6
13
13
1
5
hull tree
2
4
7
12
8
3
6
10
9
11
44
Bridging Given U1 U2 separated by vertical
line x(v), find bridge pq.
q
p
(U1 U2 are given as dictionaries)
U2
U1
x(v)
q
reflex
inflex
supporting
p
q
q
p
p
q
reflex
p
U1
U2
U1
U2
U1
U2
q
q
?
inflex
p
p
q
U1
U2
U1
U2
p
U1
U2
q
done
q
p
p
p
q
supporting
U1
U2
U1
U2
U1
U2
45
Bridging How to resolve the inflex-inflex Case
u
r
w
edge
q
edge
p
bridge must intersect this shaded area
q cant be here
U2
U1
x(v)
46
Secondary structure Q(v), at each node v, is
implemented by a dictionary (as in
Preparata79 insert-only semi-dynamic CH
algorithm).
Deletion algorithm Left as exercise.Balancing/
rotation operations do not add extra asymptotic
cost.
47
Exercises
48
  • CLRS, Exercise 33.1-5, page 939 Prove or
    disprove a sequence P ? p0, p1, , pn-1 ? of n
    points in the plane forms the boundary of a
    convex polygon if and only if , for i 0..n-1
    (mod n index arithmetic), D(pi-1, pi, pi1) are
    all positive or all negative, i.e., either all
    are left turns or all are right turns.
  • Convex hull of sorted points Show that the
    convex hull of a set P of n points in the plane
    can be computed in O(n) time if the points in P
    are already sorted on their x-coordinates. Prove
    the correctness and time complexity of your
    algorithm.
  • CLRS, Exercises 33.3-5 33.3-6, page 957
    On-line convex hull We are given a set P of n
    points in the plane, one point at a time on-line.
    Update CH(P) after receiving each point (a)
    Design and analyze a simple O(n2) time algorithm
    for this problem.(b) Design and analyze an O(n
    log n) time algorithm for this problem.
  • Convex hull in integer grid Given a planar set
    P of n points with coordinates as positive
    integers at most nd, where d is some constant,
    show CH(P) can be constructed in O(n) time.
  • Convex hull of unit circles Let S be a set of n
    given, possibly intersecting, unit circles (i.e.,
    all with radius 1) on the plane. The boundary of
    CH(S) consists of line-segments and some circular
    arcs that are pieces of circles in S.(a) Show
    that each circle can contribute at most one
    circular arc to the boundary of CH(S).(b) Let C
    be the set of n centers of the circles in S. Show
    that circle A?S contributes an arc to
    the boundary of CH(S) if and only if the center
    of A is an extreme point of C.(c) Design and
    analyze an efficient algorithm that outputs the
    boundary of CH(S). The output should be
    in the form of a finite closed chain of line
    segments and circular arcs.

49
  • CLRS, Exercise 3.1-4, page 939 Show how to
    determine in O(n2 log n) time whether any 3
    points in a set of n points in the plane are
    collinear.
  • Given a set P of n points in the plane, construct
    a simple polygon with P as its vertex set.(a)
    Show the W(n log n) lower bound on the worst-case
    time complexity of this problem.(b) Design an
    O(n log n) time algorithm for this problem.
  • Show that any set S of at least d2 points in ?d
    can be partitioned into two nonempty subsets A
    and B such that CH(A) ? CH(B) ? ? . Hint
    consider linear combinations of points in S.
  • Given a set P of n points and another point q,
    all in the plane, design an O(n) time
    algorithmto decide whether q is in CH(P).
  • We are given a set P of n points, and a
    triangular area T specified by its three vertices
    T (t1 , t2 , t3), all in the plane.(a) Design
    and analyze an O(n)-time algorithm to decide
    whether CH(P), the convex hull of P
    (interior as well as boundary), intersects with
    triangle area T. (b) Consider the modified
    version of the problem in part (a), where we want
    to decide whether the boundary of CH(P)
    intersects area T. Design and analyze an
    efficient algorithm for this problem.

50
  • Polygon distance Given two disjoint convex
    polygons P and Q in the plane, design an
    efficient algorithm to determine the closest
    pair of points between P and Q. (Note these
    points may not necessarily be vertices.)
  • Linear Circular Separability Use
    prune--search to show the linear separability
    problem can be solved in O(n) time. How about
    circular separability (?a circle that contains
    one set inside, the other outside)?
  • Linear Regression Given a set P of n points in
    the plane, determine a line L such that the
    largest vertical distance between any point of P
    to L is minimized. Show an O(n) time solution to
    this problem using prune--search.

51
END
Write a Comment
User Comments (0)
About PowerShow.com