CS 401
Master Theorem / Closest Points
Xiaorui Sun
1
CS 401 Master Theorem / Closest Points Xiaorui Sun 1 Master - - PowerPoint PPT Presentation
CS 401 Master Theorem / Closest Points Xiaorui Sun 1 Master Theorem Master Theorem % & + (" ) for all " > +. Then, Suppose ! " = $ ! c: absolute constant If $ < + ) then ! " = " ) If $ = + ) then
Xiaorui Sun
1
% & + (") for all " > +. Then,
& instead of % & .
c: absolute constant
! " = 4 Θ 1 if " = 1 3!( "/2 ) + Θ(") if " > 1
Suppose ! " = = !
> ? + @"A for
all " > B. ! " = Θ "A 4 1 if = < BA log? " if = = BA "%&'D E if = > BA
! " = if " ≤ 1 ! " 5 + ! " − 3 " 10 + 11 5 " if " > 1 Akra–Bazzi theorem Wiki!
& ' + )#* for all # > ,.
Suppose 4 ! = 6 4
7 8 + :!; for all ! > =.
4 ! = Θ !; 1 if 6 < =; log8 ! if 6 = =; 6 =;
if 6 > =;
678 97:;<= >
+
% & + (") for all " > +. Then,
# of problems increases slower than the decreases of cost. First term dominates. # of problems increases faster than the decreases of cost Last term dominates.
89: ;92345 %
)
(,-
(,-
2( means the hidden constant depends on #
:;< .;=>?@ %
)
:;< .;=>?@ %
:
=>?@ %
3456 %
: &; 3456 %
$3456 % = (/3456 :)3456 % = (/3456 %)3456 : = "3456 : /) 3456 % = /3456 % ) = ")
# pairwise distances
1 2 4 4.8 7 8.2 11 11.5 13 16 19
No single direction along which one can sort points to guarantee success!
12 21 8 L
How ?
12 21 L d=12
7 1 2 3 4 5 6
Partition each side of ! into "
# × " # squares
Claim: No two points lie in the same "
# × " # box.
Proof: Such points would be within
" # #
" # #
( # ≈ 0.7' < '
Let ./ have the 012 smallest 3-coordinate among points in the 2'-width-strip. Claim: If 0 − 6 > 11, then the distance between ./ and .
9 is > '.
Proof: only 11 boxes within ' of 3(./).
d
29 30 31 28 26 25
d
½d ½d
49
i j
27 29
> '
Closest-Pair(!", !$, ⋯ , !&) { if(& ≤ $) return |!" − !$| Compute separation line * such that half the points are on one side and half on the other side. +" = Closest-Pair(left half) +$ = Closest-Pair(right half) + = min(+", +$) Delete all points further than d from separation line L Sort remaining points p[1]…p[m] by y-coordinate. for , = ", $, ⋯ , . for k = ", $, ⋯ , "" if , + 0 ≤ . d = min(d, distance(p[i], p[i+k])); return d. }
Closest-Pair(!", !$, ⋯ , !&) { if(& ≤ $) return distance(!", !$) Compute separation line ) such that half the points are on one side and half on the other side. *" = Closest-Pair(left half) *$ = Closest-Pair(right half) * = min(*", *$) Delete all points further than d from separation line L Sort remaining points p[1]…p[m] by y-coordinate. for + = ", $, ⋯ , - for k = ", $, ⋯ , "" if + + / ≤ - d = min(d, distance(p[i], p[i+k])); return d. }
111 ≤ 112 distance calculations
Closest-Pair(!", !$, ⋯ , !&) { if(& ≤ $) return distance(!", !$) Compute separation line ) such that half the points are on one side and half on the other side. *" = Closest-Pair(left half) *$ = Closest-Pair(right half) * = min(*", *$) Delete all points further than d from separation line L Sort remaining points p[1]…p[m] by y-coordinate. for + = ", $, ⋯ , - for k = ", $, ⋯ , "" if + + / ≤ - d = min(d, distance(p[i], p[i+k])); return d. }
0(2 log 2) 0(2) 0(1) 0(2 log 2) 0(2)
Can we do better?
Closest-Pair(!", !$, ⋯ , !&) { if(& ≤ $) return distance(!", !$) Compute separation line ) such that half the points are on one side and half on the other side. (*", +") = Closest-Pair(left half) (*$, +$) = Closest-Pair(right half) * = min(*", *$) +,-./01 = merge(+", +$) (merge sort it by y-coordinate) Let 2 be points (ordered as +,-./01) that is * from line L. for 3 = ", $, ⋯ , 5 for k = ", $, ⋯ , "" if 3 + 7 ≤ 5 d = min(d, distance(S[i], S[i+k])); return d and +,-./01. }
Input sorted by y-coordinate Assume: input sorted by x-coordinate (O(n log n) overhead initially)
?(1) ?(9) ?(1) ?(9) ?(9)