Computatoal Geometry Chapter 6 Pot Locato 1 Problem Defto Preprocess a plaar map S. Gve a query pot p, report the face of S cotag p. S Goal: O()-sze data structure that eables O(log ) query tme. C p E F pplcato: Whch state s altmore located? swer: Marylad D G Trval Soluto: O() query tme, where s the complexty of the map. (Questo: Why s the query tme oly O()?) 2 1
Naïve Soluto Draw vertcal les through all the vertces of the subdvso. Store the x-coordates of the vertces a ordered bary tree. Wth each slab, sort the segmets separately alog y. Query tme: O(log ). Problem: Too delcate subdvso, of sze ( 2 ) the worst case. (Gve such a example!) 3 The Trapezodal Map Costruct a boudg box. ssume geeral posto: uque x coordates. Exted upward ad dowward the vertcal le from each vertex utl t touches aother segmet. Ths works also for ocrossg le segmets. 4 2
Propertes Cotas tragles ad trapezods. Each trapezod or tragle s determed: y two vertces that defe vertcal sdes; ad y two segmets that defe overtcal sdes. refemet of the orgal subdvso. 5 Notato Every trapezod (or tragle) s defed by Left(): a segmet edpot (rght or left); Rght(): a segmet edpot (rght or left); Top(): a segmet; ottom(): a segmet. 6 3
Complexty Theorem (lear complexty): trapezodal map of segmets cotas at most 6+4 vertces ad at most 3+1 faces. Proof: 1. Vertces: 2 + 4 + 4 = 6 + 4 orgal extesos box 2. Faces: Cout Left(). 2 + + 1 = 3 + 1 left e.p. rght e.p. box Questo: Why does the proof hold for degeerate stuatos? 7 Possbly by DCEL. Map Data Structure alteratve: For each trapezod store: The vertces that defe ts rght ad left sdes; The top ad bottom segmets; The (up to two) eghborg trapezods o rght ad left; (Optoal) The eghborg trapezods from above ad below. Ths umber mght be lear, so oly the leftmost of these trapezods s stored. Note: Computg ay trapezod from the trapezodal structure ca be doe costat tme. 8 4
Search Structure: rachg Rules Query pot q, search-structure ode s. s s a segmet edpot: q s to the rght of s: go rght; q s to the left of s: go left; s s a segmet: q s below s: go rght; q s above s: go left; 9 The DG Search Structure Q 1 P 1 Q 2 S 1 S 3 Q 3 S 1 E S 3 D P 3 Q 3 H J Q 1 F P 1 Q 2 C P S 2 2 G K P 3 P 2 S 3 C S 2 S 2 S 3 D E F G D H J K 10 5
Usg the Search Structure Q 1 P 1 Q 2 S 1 S 3 Q 3 S 1 E S 3 D P 3 Q 3 H J Q 1 F P 1 Q 2 C P S 2 2 G K P 3 P 2 S 3 C S 2 S 2 S 3 D E F G D H J K 11 Search Structure: Costructo Fd a oudg ox. Radomly permute the segmets. Isert the segmets oe by oe to the map. Update the map ad search structure each serto. The sze of the map s (). ) (Ths was prove earler.) The sze of the search structure depeds o the order of serto. 12 6
Updatg the Structures (Hgh Level) Fd the exstg structure the face that cotas the left edpot of the ew segmet. (*) () Fd all other trapezods tersected by ths segmet by movg to the rght. (I each move choose betwee two optos: Up or Dow.) Update the map M ad the search structure D. (*) Note: Sce edpots may be shared by segmets, we eed to cosder ts segmet whle searchg. 13 Update: Smple Case The segmet s cotaed etrely oe trapezod. I M -1 : Splt the trapezod to four trapezods. I D -1 : The leaf wll be replaced by a subtree. T Everythg s P doe O(1) tme. Q P C M -1 Q D S C D 14 7
Update M: : Geeral Case Geeral Case: The th segmet tersects wth k >1 trapezods. Splt trapezods. Merge trapezods that ca be uted. Total update tme: O(k ). 15 Updatg D: : Splt Each er trapezod D -1 s replaced by: S Each outer (e.g., left) trapezod D -1 s replaced by: P S C 16 8
Updatg D: : Merge Leaves are elmated ad replaced by oe commo leaf. Total update tme: O(k ). G H L C KD E F S S S S G H C D E F L K 17 Costructo: Worst-Case alyss Each segmet adds trees of depth at most (4-1=) 3, so the depth of D s at most 3. Query tme (depth of D ): O(), () the worst case. The th segmet, s, may tersect wth O() trapezods (() the worst case)! The sze of D ad ts costructo tme are the bouded from above by O( ) O( 2 ). 1 18 9
Costructo: Worst-Case alyss (cot.) Worst-case example: 19 Costructo: Worst-Case alyss (cot.) Worst-case example: O() 20 10
Costructo: Worst-Case alyss (cot.) Worst-case example: The sze of D ad ts costructo tme s the worst case. 2 1 (1) 1 2 ( ) ( 21 2 ) verage-case alyss We frst look for the expected depth of D. q: pot, to be searched for D. p : The probablty that a ew vertex was created the path leadg to q the th terato. Compute p by backward aalyss: q (M -1 ): The trapezod cotag q M -1. Sce a ew vertex was created, q (M ) q (M -1 ). Delete s from M. p = Prob[ q (M ) q (M -1 )] 4/. (Why?) 22 11
Expected Depth of D x : The umber of vertces created the th terato the path leadg to the leaf q. q The expected legth of the path leadg to q: E 1 x 12 Ex (3p ) O(log ). 1 1 1 23 Defe a dcator Expected Sze of D 1 dsappears from M (, s ) 0 otherwse f s k : Number of leaves created the th step. S : The set of the frst segmets. verage o s: 1 1 E[ k ] (, ) (, ) s s ss M ss M 1 (4 M ) (same backward aalyss) O( ) O(1). s removed 24 12
Expected Sze of D (cot.) k -1: Number of teral odes created the th step. Total sze: O( ) E leaves 1 ( k 1) O( ) E teral 1 k O( ). s 25 Expected Costructo Tme of D 1 O( E(depth )) O(E[ k ( O(log) O(1)) O( log ) 1 ]) Fdg the frst trapezod The rest of the work the th step 26 13
Hadlg Degeeraces What happes f two segmet edpots have the same x coordate? Use a shearg trasformato: x x y y y Hgher pots wll move more to the rght. should be small eough so that ths trasform wll ot chage the order of two pots wth dfferet x coordates. I fact, there s o eed to shear the plae. Comparso rules mmc the shearg. Prove: The etre algorthm remas correct. 27 14