chan alg
TRANSCRIPT
-
8/10/2019 chan alg
1/5
2. Chans Algorithm
2.1 Graham Scan (Successive Local Repair)
(p1, . . . , pn)
p10p4
p1
p3
p2
p5
p9
p7p6
p10p4p1p3p2p5p9p7p6p7p9p5p2p3p1p4p10
(p, q, r)
q
pr q
Theorem 2.1 P R2 n O(n
n)
Proof.
O(n
n)
2n 2
h
2n h 2
2n 2
4nh4
O(n n)
O(n
n)
2.2 Lower Bound
Theorem 2.2 (n n)
n
R2
Proof. (n n)
n
x1, . . . , xn
P = {pi| 1 i n} n R
2
pi = (xi, x2i
)
R2
x
7
-
8/10/2019 chan alg
2/5
P
xi o(n n)
o(n
n)
(n
n)
(n n)
n
2.3 Jarvis Wrap and Graham Scan in C++
Jarvis Wrap.
p[0..N)
p start x
q next
p[0..N)
int h = 0;Point_2 q_now = p_start;
do {
q[h] = q_now;
h = h + 1;
f o r ( i n t i = 0 ; i < N ; i = i + 1 )
if (rightturn_2(q_now, q_next, p[i]))
q_next = p[i];
q_now = q_next;
q_next = p_start;
} while (q_now != p_start);
q[0,h)
p[0..N)
Graham Scan.
p[0..N) N 2
q[0] = p[0];
int h = 0;
8
-
8/10/2019 chan alg
3/5
// Lower convex hull (left to right):
f o r ( i n t i = 1 ; i < N ; i = 1 + 1 ) {
while (h>0 && rightturn_2(q[h-1], q[h], p[i]))h = h - 1;
h = h + 1;
q[h] = p[i];
}
// Upper convex hull (right to left):
for (int i = N-2; i >= 0; i = i - 1) {
while (rightturn_2(q[h-1], q[h], p[i]))
h = h - 1;
h = h + 1;q[h] = p[i];
}
q[0,h)
p[0..N)
2.4 Chans Algorithm
O(nh) (n n) h= o( n)
Divide.
P
R2
n
H {1 , . . . , n}
P k= n/H P1, . . . , Pk |Pi| H
(
)
i 1
i
k
H ( )
O(n)
O(H H) Pi O(n H)
Conquer.
(
) i 1 i k
9
-
8/10/2019 chan alg
4/5
P
H
(
)
( )
(
)
(
) 1 i k
O(n)
H
k
H
O(Hk
H) =O(n
H)
O(n)
O(n H)
Searching for h.
H= h
h
H =
{22
t
, n}
t =
0 , . . . P
22s
H = 22
s1
22
s1
< h
2s1