A Dynamic Stabbing-Max Data Structure with Sub-Logarithmic Query Time

In this paper we describe a dynamic data structure that answers one-dimensional stabbing-max queries in optimal $O(\log n/\log\log n)$ time. Our data structure uses linear space and supports insertions and deletions in $O(\log n)$ and $O(\log n/\log …

Authors: Yakov Nekrich

A Dynamic Stabbing-Max Data Structure with Sub-Logarithmic Query Time
A Dynamic Stabbing-Max Data Structure with Sub-Logarithmic Query Time Y ak o v Nekric h ∗ Abstract In this pap er w e describ e a dynamic data structure that answers one-dimensional stabbing- max queries in optimal O (log n/ log log n ) time. Our data structure uses linear space and sup- p orts insertions and deletions in O (log n ) and O (log n/ log log n ) amortized time resp ectively . W e also describ e a O ( n (log n/ log log n ) d − 1 ) space data structure that answ ers d -dimensional stabbing-max queries in O ((log n/ log log n ) d ) time. Insertions and deletions are supp orted in O ((log n/ log log n ) d log log n ) and O ((log n/ log log n ) d ) amortized time resp ectively . 1 In tro duction In the stabbing-max problem, a set of rectangles is stored in a data structure, and each rectangle s is assigned a priority p ( s ). F or a query p oin t q , we m ust find the highest priorit y rectangle s that con tains (or is stabb ed b y) q . In this pap er w e describ e a dynamic data structure that answ ers stabbing-max queries on a set of one-dimensional rectangles (in terv als) in optimal O (log n/ log log n ) time. W e also show how this result can b e extended to d > 1 dimensions. Previous W ork. The stabbing-max problem has imp ortant applications in netw orking and geographic information systems. Solutions to some special cases of the stabbing-max problem play a crucial role in classification and routing of Internet pack ets; we refer to e.g., [9, 11, 18] for a small selection of the previous w ork and to [10, 19] for more extensiv e surv eys. Belo w w e describ e the previous w orks on the general case of the stabbing-max problem. The semi-dynamic data structure of Y ang and Widom [24] maintains a set of one-dimensional in terv als in linear space; stabbing-max queries and insertions are supported in O (log n ) time. Agar- w al et al. [1] show ed that stabbing-max queries on a set of one-dimensional interv als can b e answered in O (log 2 n ) time; the data structure of Agarwal et al. [1] uses linear space and supp orts up dates in O (log n ) time. The linear space data structure of Kaplan et al. [15] supports one-dimensional queries and insertions in O (log n ) time, but deletions tak e O (log n log log n ) time. In [15], the authors also consider the stabbing-max problem for a nested set of interv als: for any tw o in terv als s 1 , s 2 ∈ S , either s 1 ⊂ s 2 or s 2 ⊂ s 1 or s 1 ∩ s 2 = ∅ . Their data structure for a nested set of one-dimensional in terv als uses O ( n ) space and supp orts b oth queries and up dates in O (log n ) time. Thorup [22] describ ed a linear space data structure that supp orts v ery fast queries, but needs log ω (1) n time to p erform up dates. His data structure supp orts stabbing-max queries in O ( ` ) time and up dates in O ( n 1 /` ) time for any parameter l = o (log n/ log log n ). Ho w ever the problem of constructing a data ∗ Departmen t of Computer Science, Univ ersit y of Chile. Supp orted in part by Millennium Institute for Cell Dy- namics and Biotechnology (ICDB), Gran t ICM P05-001-F, Mideplan, Chile. Email yakov.nekrich@googlemail.com . 1 structure with p oly-logarithmic up date time is not addressed in [22]. Agarwal et al. [2] describ ed a data structure that uses linear space and supp orts b oth queries and up dates in O (log n ) time for an arbitrary set of one-dimensional interv als. The results presented in [15] and [2] are v alid in the p oin ter mac hine mo del [20]. The one-dimensional data structures can b e extended to d > 1 dimensions, so that space usage, query time, and up date time increase by a factor of O (log d − 1 n ). Th us the b est previously kno wn data structure [2] for d -dimensional stabbing-max problem uses O ( n log d − 1 n ) space, answers queries in O (log d n ) time, and supp orts up dates in O (log d n ) time. Kaplan et al. [15] show ed that d -dimensional stabbing-max queries can be answ ered in O (log n ) time for any constant d in the sp ecial case of nested rectangles. Our Result. The one-dimensional data structure describ ed in [2] ac hiev es optimal query time in the p ointer machine mo del. In this paper w e sho w that w e can ac hieve sublogarithmic query time without increasing the up date time in the word RAM mo del of computation. Our data structure supp orts deletions and insertions in O (log n/ log log n ) and O (log n ) amortized time resp ectively . As follo ws from the low er b ound of [3], any fully-dynamic data structure with p oly-logarithmic up date time needs Ω(log n/ log log n ) time to answer a stabbing-max query 1 . Th us our data structure ac hiev es optimal query time and space usage. Our result can b e also extended to d > 1 dimensions. W e describ e a data structure that uses O ( n (log n/ log log n ) d − 1 ) space and answ ers stabbing-max queries in O ((log n/ log log n ) d ) time; insertions and deletions are supp orted in O ((log n/ log log n ) d log log n ) and O ((log n/ log log n ) d ) amortized time resp ectively . Moreov er, our construction can b e mo dified to supp ort stabbing-sum 2 queries: w e can coun t the num ber of one-dimensional interv als stabb ed b y a query point q in O (log n/ log log n ) time. The stabbing-sum data structure also supports insertions and deletions in O (log n ) and O (log n/ log log n ) amortized time. Ov erview. W e start by describing a simple one-dimensional stabbing-max data structure in section 2. This data structure ac hiev es the desired query and up date times but needs ω ( n 2 ) space. All in terv als are stored in nodes of the base tree of heigh t O (log n/ log log n ); the base tree is organized as a v ariant of the segment tree data structure. Interv als in a no de u are stored in a v ariant of the v an Emde Boas (VEB) data structure [8]. W e can answer a stabbing-max query by tra v ersing a leaf-to-ro ot path in the base tree; the pro cedure sp ends O (1) time in each no de on the path. In section 3, we show how all secondary data structures in the no des of the base tree can b e stored in O ( n log n ) bits of space. The main idea of our metho d is the compact representation of in terv als stored in each no de. Similar compact representations were also used in data structures for range rep orting queries [6, 16] and some other problems [5]. Ho w ev er the previous metho ds are to o slow for our goal: we need O (log log n ) time to obtain the representation of an element e in a no de u if the represen tation of e in a child of u is known. Therefore it w ould tak e O (log n ) time to tra v erse a leaf-to-ro ot path in the base tree. In this pap er we presen t a new, improv ed compact storage sc heme. Using our represen tation, w e can tra verse a path in the base tree and sp end O (1) time in each no de. W e b elieve that our metho d is of indep endent in terest and can b e also applied to other problems. 1 In fact, the lo wer b ound of [3] is v alid ev en for existen tial stabbing queries: Is there an in terv al in the set S that is stabb ed by a query p oint q ? 2 The stabbing-sum problem considered in this pap er is to be distinguished from the more general stabbing-group problem, in which ev ery interv al is asso ciated with a weigh t drawn from a group G . 2 α β γ δ w u Figure 1: In ternal no des of the base tree. In terv als α and δ are stored in the set S ( w ), but are not stored in the set S ( u ). In terv al γ is stored in S ( u ), but γ is not stored in S ( w ). In terv al β is stored in b oth S ( u ) and S ( w ). Moreov er, α , β , and δ b elong to the sets S 23 ( w ), S 33 ( w ), and S 33 ( w ) resp ectiv ely . Interv als β and γ b elong to S 24 ( u ) and S 23 ( u ) resp ectiv ely . The results for multi-dimensional stabbing-max queries and stabbing-sum queries are describ ed in Theorems 2 and 3; an extensive description of these results is pro vided in App endices C and D. 2 A Data Structure with Optimal Query Time Base T ree. In this section we describ e a data structure that answers stabbing-max queries in optimal time. Endp oints of all interv als from the set S are stored in the leav es of the base tree T . Ev ery leaf of T con tains Θ(log ε n ) endpoints. Ev ery in ternal node, except of the ro ot, has Θ(log ε n ) c hildren; the root has O (log ε n ) c hildren. Throughout this paper ε denotes an arbitrarily small p ositive constant. The range r ng ( u ) of a no de u is an in terv al b ounded b y the minimal and maximal v alues stored in the leaf descendants of u . F or a leaf no de u l , the set S ( u l ) con tains all interv als s , such that at least one endp oint of s b elongs to u l . F or an internal no de u , the set S ( u ) contains all interv als s , such that r ng ( u i ) ⊂ s for at least one child u i of u but r ng ( u ) 6⊂ s . See Fig. 1 for an example. Th us each in terv al is stored in O (log n/ log log n ) sets S ( u ). F or every pair i ≤ j , S ij ( u ) denotes the set of all interv als s ∈ S ( u ) suc h that r ng ( u f ) ⊂ s for a child u f of u if and only if i ≤ f ≤ j . F or simplicity , w e will sometimes not distinguish b et w een interv als and their priorities. Secondary Data Structures. F or eac h internal no de u , w e store a data structure D ( u ) describ ed in the follo wing Prop osition. Prop osition 1 Supp ose that priorities of al l intervals in S ( u ) ar e inte gers in the interval [1 , p max ] for p max = O ( n ) . Ther e exists a data structur e D ( u ) that uses O ( p max · log 2 ε n ) wor ds of sp ac e 3 and supp orts the fol lowing queries: for any l ≤ r , the pr e de c essor of q in S lr ( u ) c an b e found in O (log log n ) time and the maximum element in S lr ( u ) c an b e found in O (1) time. The data structur e supp orts insertions in O (log log n ) time. If a p ointer to an interval s ∈ S ( u ) is given, s c an b e delete d in O (1) amortize d time. Pr o of : It suffices to store all interv als from S lr ( u ) in a VEB data structure D lr ( u ). Eac h D lr ( u ) uses O ( p max ) w ords of space and answers queries in O (log log p max ) = O (log log n ) time [8]. It is a folklore observ ation that w e can mo dify the VEB data structure so that maxim um queries are supp orted in constan t time.  W e also store a data structure M ( u ) that con tains the in terv al max ij ( u ) with maximal priority among all interv als in S ij ( u ) for each i ≤ j . Since each internal no de has Θ(log ε n ) c hildren, M ( u ) con tains O (log 2 ε n ) elements. F or an y query index f , M ( u ) rep orts the largest element among all max ij , i ≤ f ≤ j . In other words for any child u f of u , M ( u ) can find the in terv al with the highest priorit y that co v ers the range of the f -th child of u . Using standard techniques, we can implement M ( u ) so that queries and up dates are supp orted in O (1) time. F or completeness, we describe the data structure M ( u ) in Appendix A. Queries and Up dates. Let π denote the search path for the query p oint q in the base tree T . The path π consists of the nodes v 0 , v 1 , . . . , v R where v 0 is a leaf no de and v R is the ro ot no de. Let s ( v i ) be the interv al with the highest priorit y among all interv als that are stored in ∪ j ≤ i S ( v j ) and are stabb ed b y q . The interv al s ( v 0 ) can b e found b y examining all O (log ε n ) in terv als stored in S ( v 0 ). Supp ose that we reached a no de v i and the interv al s ( v i − 1 ) is already known. If q stabs an in terv al s stored in S ( v i ), then rng ( v i − 1 ) ⊂ s . Therefore q stabs an interv al s ∈ S ( v i ) if and only if s is stored in some set S lr ( v i ) such that l ≤ f ≤ r and v i − 1 is the f -th c hild of v i . Using the data structure M ( v i ), we can find in constan t time the maximal interv al s m , such that s m ∈ S lr ( v i ) and l ≤ f ≤ r . Then w e just set s ( v i ) = max( s m , s ( v i − 1 )) and pro ceed in the next node v i +1 . The total query time is O (log n/ log log n ). When we insert an in terv al s , we identify O (log n/ log log n ) nodes v i suc h that s is to b e inserted in to S ( v i ). F or every such v i , we pro ceed as follows. W e identify l and r such that s b elongs to S lr ( v i ). Using D ( v i ), w e find the p osition of s in S lr ( v i ), and insert s in to S lr ( v i ). If s is the maximal interv al in S lr ( v i ), we delete the old interv al max lr ( v i ) from the data structure M ( v i ), set max lr ( v i ) = s , and insert the new max lr ( v i ) in to M ( v i ). When an in terv al s is deleted, w e also identify no des v i , suc h that s ∈ S ( v i ). F or each v i , w e find the indices l and r , such that s ∈ S lr ( v i ). Using the pro cedure that will b e describ ed in the next section, we can find the p osition of s in S lr ( v i ). Then, s is deleted from the data structure D ( v i ). If s = max lr ( v i ), we remov e max lr ( v i ) from M ( v i ), find the maximum priority interv al in S lr ( v i ), and insert it in to M ( v i ). W e will show in section 3 that p ositions of the deleted interv al s in S lr ( v i ) for all no des v i can b e found in O (log n/ log log n ) time. Since all other op erations take O (1) time p er no de, the total time necessary for a deletion of an interv al is O (log n/ log log n ). Unfortunately , the space usage of the data structure describ ed in this section is v ery high: every VEB data structure D lr ( u ) needs O ( p max ) space, where p max is the highest p ossible in terv al priorit y . Ev en if p max = O ( n ), all data structures D ( u ) use O ( n 2 log 2 ε n ) space. In the next section we show ho w all data structures D ( u ), u ∈ T , can b e stored in O ( n log n ) bits without increasing the query and up date times. 4 3 Compact Represen tation The k ey idea of our compact representation is to store only in terv al identifiers in every no de u of T . Our storage scheme enables us to sp end O (log log n ) bits for eac h iden tifier stored in a no de u . Using the p osition of an interv al s in a no de u , we can obtain the p osition of s in the parent w of u . W e can also compare priorities of tw o in terv als stored in the same no de by comparing their p ositions. These prop erties of our storage sc heme enable us to trav erse the searc h path for a p oint q and answer the query as describ ed in section 2. Similar representations were also used in space-efficien t data structures for orthogonal range rep orting [6, 16] and orthogonal point lo cation and line-segmen t intersection problems [5]. Storage sc hemes of [16, 5] also use O (log log n ) bits for each interv al stored in a no de of the base tree. The main dra wbac k of those methods is that we need O (log log n ) time to navigate b etw een a no de and its parent. Therefore, Θ(log n ) time is necessary to tra v erse a leaf-to-ro ot path and w e need Ω(log n ) time to answ er a query . In this section we describ e a new metho d that enables us to na vigate b et w een no des of the base tree and up date the lists of identifiers in O (1) time p er no de. The main idea of our impro v emen t is to main tain iden tifiers for a set S ( u ) ⊃ S ( u ) in every u ∈ T . When an interv al is inserted in S ( u ), we also add its identifier to S ( u ). But when an interv al is deleted from S ( u ), its identifier is not remov ed from S ( u ). When the num b er of deleted interv al iden tifiers in all S ( u ) exceeds the num ber of interv als in S ( u ), we re-build the base tree and all secondary structures (global re-build). Compact Lists. W e start b y defining a set S 0 ( u ) ⊃ S ( u ). If u is a leaf no de, then S 0 ( u ) = S ( u ). If u is an in ternal node, then S 0 ( u ) = S ( u ) ∪ ( ∪ i S 0 ( u i )) for all c hildren u i of u . An interv al s b elongs to S 0 ( u ) if at least one endp oint of s is stored in a leaf descendan t of u . Hence, | ∪ v S 0 ( v ) | = O ( n ) where the union is taken ov er all no des v that are situated on the same lev el of the base tree T . Since the height of T is O (log n/ log log n ), the total n umber of interv als stored in all S 0 ( u ), u ∈ T , is O ( n log n/ log log n ). Let S ( u ) b e the set that contains all in terv als from S 0 ( u ) that were inserted into S 0 ( u ) since the last global re-build. W e will organize global re-builds in such wa y that at most one half of elements in all S ( u ) corresp ond to deleted interv als. Therefore the total num ber of interv als in ∪ u ∈ T S ( u ) is O ( n log n/ log log n ). W e will show b elow how we can store the represn tations of sets S ( u ) in compact form, so that an element of S ( u ) uses O (log log n ) bits in a v erage. Since S ( u ) ⊂ S ( u ), we can also use the same metho d to store all S ( u ) and D ( u ) in O ( n log n ) bits. Sets S 0 ( u ) and S ( u ) are not stored explicitly in the data structure. Instead, w e store a list Comp ( u ) that contains a compact represen tation for identifiers of in terv als in S ( u ). Comp ( u ) is organized as follo ws. The set S ( u ) is sorted by interv al priorities and divided into blo cks. If | S ( u ) | > log 3 n/ 2, then eac h blo c k of S ( u ) con tains at least log 3 n/ 2 and at most 2 log 3 n elements. Otherwise all e ∈ S ( u ) b elong to the same blo ck. Each blo ck B is assigned an integer blo c k lab el lab ( B ) according to the metho d of [14, 23]. Lab els of blo cks are monotone with resp ect to order of blo c ks in Comp ( u ): The blo ck B 1 precedes B 2 in Comp ( u ) if and only if lab ( B 1 ) < lab ( B 2 ). Besides that, all lab els assigned to blocks of Comp ( u ) are b ounded b y a linear function of | Comp ( u ) | / log 3 n : for any blo c k B in Comp ( u ), lab ( B ) = O ( | Comp ( u ) | / log 3 n ). When a new blo ck is inserted into a list, w e ma y ha ve to change the lab els of O (log 2 n ) other blo c ks. F or ev ery blo c k B , w e store its blo ck lab el as w ell as the p ointers to the next and the previous blo c ks in the list Comp ( u ). F or eac h interv al ¯ s in a blo ck B of S ( u ), the list Comp ( u ) con tains the identifier of ¯ s in Comp ( u ). The identifier is simply the list of indices of children u i of u , such that ¯ s ∈ Comp ( u i ). As follo ws from the description of the base tree and the sets S ( u ), we store at most 5 t w o child indices for every interv al ¯ s in a blo ck; hence, eac h identifier uses O (log log n ) bits. T o simplify the description, we sometimes will not distinguish b etw een an in terv al s and its identifier in a list Comp ( u ). W e say that the p osition of an interv al s in a list Comp ( u ) is kno wn if the blo ck B that contains s and the position of s in B are kno wn. If we know p ositions of tw o interv als s 1 and s 2 in Comp ( u ), w e can compare their priorities in O (1) time. Supp ose that s 1 and s 2 b elong to blocks B 1 and B 2 resp ectiv ely . Then s 1 > s 2 if lab ( B 1 ) > lab ( B 2 ), and s 1 < s 2 if lab ( B 1 ) < lab ( B 2 ). If lab ( B 1 ) = lab ( B 2 ), we can compare priorities of s 1 and s 2 b y comparing their p ositions in the blo c k B 1 = B 2 . The rest of this section has the follo wing structure. First, we describ e auxiliary data structures that enable us to search in a blo ck and na vigate b etw een no des of the base tree. Each blo c k B con tains a p oly-logarithmic num ber of elements and every iden tifier in B uses O (log log n ) bits. W e can use this fact and implement block data structures, so that queries and up dates are supp orted in O (1) time. If the p osition of some ¯ s in a list Comp ( u ) is known, we can find in constant time the p ositions of ¯ s in the paren t of u . Next, we show ho w data structures D ( u ) and M ( u ), defined in section 2, are mo dified. Finally , we describ e the search and up date pro cedures. Blo c k Data Structures. W e store a data structure F ( B ) that supp orts rank and select queries in a blo ck B of Comp ( u ): A query rank ( f , i ) returns the num b er of in terv als that also b elong to S ( u f ) among the first i elements of B . A query select ( f , i ) returns the smallest j , suc h that rank ( f , j ) = i ; in other words, select ( f , i ) returns the p osition of the i -th interv al in B that also b elongs to S ( u f ). W e can answ er rank and select queries in a blo ck in O (1) time. W e can also coun t the n um b er of elemen ts in a blo c k of Comp ( u ) that are stored in the f -th child of u , and determine for the r -th element of a blo ck in which children of u it is stored. Implementation of F ( B ) will b e describ ed in App endix A. F or each blo ck B j ∈ Comp ( u ) and for any child u f of u , we store a p oin ter to the largest blo ck B f j b efore B j that con tains an element from Comp ( u f ). These p ointers are maintained with help of a data structure P f ( u ) for each child u f . W e implemen t P f ( u ) as an incremental split-find data structure [13]. Insertion of a new blo ck lab el into P f ( u ) tak es O (1) amortized time; w e can also find the blo ck B f j for any blo ck B j ∈ Comp ( u ) in O (1) worst-case time. Using the data structure F ( B j ) for a blo ck B j , we can identify for an y element e in a blo ck B j the largest e f ≤ e , e f ∈ B j , suc h that e f b elongs to Comp ( u f ). Thus we can identify for any e ∈ Comp ( u ) the largest element e f ∈ Comp ( u ), suc h that e f ≤ e and e f ∈ Comp ( u f ), in O (1) time. Na vigation in No des of the Base T ree. Finally , we store p ointers to selected elemen ts in eac h list Comp ( u ). Poin ters enable us to navigate b etw een no des of the base tree: if the p osition of some e ∈ Comp ( u ) is kno wn, w e can find the p osition of e in Comp ( w ) for the parent w of u and the p osition of e in Comp ( u i ) for an y c hild u i of u suc h that Comp ( u i ) con tains e . W e associate a stamp t ( e ) with eac h element stored in a blo c k B ; every stamp is a p ositiv e in teger b ounded b y O ( | B | ). A p oin ter to an element e in a block B consists of the blo ck lab el lab ( B ) and the stamp of e in B . When an elemen t is inserted into a block, stamps of other elemen ts in this blo ck do not change. Therefore, when a new interv al is inserted into a blo ck B w e do not hav e to up date all p oin ters that p oin t into B . F urthermore, w e store a data structure H ( B ) for each blo ck B . Using H ( B ), w e can find the p osition of an element e in B if its stamp t ( e ) in B is known. If an element e must b e inserted in to B after an element e p , then we can assign a stamp t e to e and insert it into H ( B ) in O (1) time. Implementation of H ( B ) is v ery similar to the implemen tation of F ( B ) and will b e describ ed in the full v ersion. 6 Comp( u ) Comp( u i ) Figure 2: P aren t and child p oin ters in blo cks of Comp ( u ) and Comp ( u i ). Interv als that are stored in Comp ( u i ) are depicted b y circles; filled circles are interv als with p ointers. Only relev an t interv als and p oin ters are sho wn in Comp ( u ). In Comp ( u i ), only paren t p oin ters are shown. If e is the first element in the blo c k B of Comp ( u ) that b elongs to Comp ( u i ), then we store the p oin ter from the copy of e in Comp ( u ) to the copy of e in Comp ( u i ). If an element e ∈ Comp ( u ) is also stored in Comp ( u i ) and e is the first element in a blo c k B 0 of Comp ( u i ), then there is a p ointer from the cop y of e in Comp ( u ) to the cop y of e in Comp ( u i ). Suc h p oin ters will b e called c hild p oin ters. F or any p ointer from e ∈ Comp ( u ) to e ∈ Comp ( u i ), we store a p ointer from e ∈ Comp ( u i ) to e ∈ Comp ( u ). Such p ointers will b e called parent pointers. See Fig. 2 for an example. W e can store each p ointer in O (log n ) bits. The total num ber of p ointers in Comp ( u ) equals to the n um b er of blo cks in Comp ( u ) and Comp ( u i ) for all children u i of u . Hence, all p ointers and all blo c k data structures use O ( n log n ) bits. If we kno w the p osition of some interv al s in Comp ( v ), we can find the p osition of s in the parent w of v as follo ws. Supp ose that an in terv al s is stored in the blo ck B of Comp ( v ) and v is the f -th c hild of w . W e find the last in terv al s 0 in B stored b efore s , such that there is a paren t p ointer from s 0 . Let m denote the num b er of elements b etw een s 0 and s in B . Let B 0 b e the blo c k in Comp ( w ) that contains s 0 . Using H ( B 0 ), we find the p osition m 0 of s 0 in the blo ck B 0 of Comp ( w ). Then the p osition of s in B 0 can b e found by answ ering the query select ( f , rank ( f , m 0 ) + m ) to a data structure F ( B 0 ). Using a symmetric pro cedure, we can find the p osition of s in Comp ( v ) if its p osition in Comp ( w ) is kno wn. Ro ot and Lea v es of the Base T ree. Elements of S ( v R ) are explicitly stored in the root no de v R . That is, we store a table in the ro ot no de v R that enables us to find for any in terv al s the blo ck B that con tains the iden tifier of s in Comp ( v R ) and the stamp of s in B . Con v ersely , if the p osition of s in a blo ck B of Comp ( v R ) is known, we can find its stamp in B in O (1) time. If the blo ck lab el and the stamp of an in terv al s are known, we can iden tify s in O (1) time. In the same w a y , w e explicitly store the elements of S ( u l ) for eac h leaf no de u l . Moreo ver, we store all elemen ts of S ( v R ) in a data structure R , so that the predecessor and the successor of an y v alue x can b e found in O (log n/ log log n ) time. Data Structures M ( u ) and D ( u ) . Each set S ( u ) and data structure D ( u ) are also stored in compact form. D ( u ) consists of structures D lr ( u ) for every pair l ≤ r . If a blo ck B contains a lab el of an in terv al s ∈ S lr ( u ), then w e s tore the lab el of B in the VEB data structure D lr ( u ). The data 7 structure G ( B ) con tains data ab out in terv als in S ( u ) ∩ B . F or ev ery s ∈ G ( B ), we store indices l, r if s ∈ S lr ( u ); if an elemen t s ∈ B does not b elong to S (i.e., s was already deleted), then we set l = r = 0. F or a query index f , G ( B ) returns in O (1) time the highest priority in terv al s ∈ B , suc h that s ∈ S lr ( u ) and l ≤ f ≤ r . A data structure G ( B ) uses O ( | B | log log n ) bits of space and supp orts up dates in O (1) time. Implemen tation of G ( B ) is very similar to the implementation of F ( B ) and will b e describ ed in the full v ersion of this pap er. W e store a data structure M ( u ) in ev ery no de u ∈ T , suc h that Comp ( u ) consists of at least tw o blo cks. F or each pair l ≤ r , the data structure M ( u ) stores the lab el of the blo ck that contains the highest priorit y interv al in S lr ( u ). F or a query f , M ( u ) returns the lab el of the blo c k that con tains the highest priority in terv al in ∪ l ≤ f ≤ r S lr ( u ). Suc h queries are supp orted in O (1) time; a more detailed description of the data structure M ( u ) will be given in Appendix A. Searc h Pro cedure. W e can easily mo dify the search pro cedure of section 2 for the case when only lists Comp ( u ) are stored in eac h no de. Let v i b e a no de on the path π = v 0 , . . . v R , where π is the search path for the query p oint q . Let s ( v i ) denote the in terv al that has the highest priority among all interv als that b elong to ∪ j ≤ i S ( v j ) and are stabb ed by q . W e can examine all interv als in S ( v 0 ) and find s ( v 0 ) in O (log ε n ) time. The p osition of s ( v 0 ) in Comp ( v 0 ) can also b e found in O (1) time. During the i -th s tep, i ≥ 1, we find the p osition of s ( v i ) in Comp ( v i ). An interv al s in S ( v i ) is stabb ed b y q if and only if s ∈ S lr ( v i ), l ≤ f ≤ r , and v i − 1 is the f -th child of v i . Using M ( v i ), w e can find the blo ck lab el of the maximal interv al s m among all interv als stored in S lr ( v i ) for l ≤ f ≤ r . Let B m b e the blo c k that contains s m . Using the data structure G ( B m ), we can find the p osition of s m in B m . By definition, s ( v i ) = max( s m , s ( v i − 1 )). Although we hav e no access to s m and s ( v i − 1 ), we can compare their priorities by comparing p ositions of s m and s ( v i − 1 ) in Comp ( v i ). Since the p osition of s ( v i − 1 ) in Comp ( v i − 1 ) is already known, w e can find its p osition in Comp ( v i ) in O (1) time. W e can also determine, whether s m precedes or follows s ( v i − 1 ) in Comp ( v i ) in O (1) time. Since a query to M ( v i ) also takes O (1) time, our search pro cedure sp ends constan t time in each no de v i for i ≥ 1. When w e kno w the p osition of s ( v R ) in Comp ( v R ), we can find the interv al s ( v R ) in O (1) time. The in terv al s ( v R ) is the highest priority interv al in S that is stabb ed b y q . Hence, a query can b e answ ered in O (log n/ log log n ) time. W e describ e ho w our data structure can b e up dated in section 4. Our result is summed up in the follo wing Theorem. Theorem 1 Ther e exists a line ar sp ac e data structur e that answers ortho gonal stabbing-max queries in O (log n/ log log n ) time. This data structur e supp orts insertions and deletions in O (log n ) and O (log n/ log log n ) amortize d time r esp e ctively. 4 Up dates in the Data Structure of Theorem 1 Supp ose that an interv al s is inserted into S . The insertion pro cedure consists of t wo parts. First, w e insert s in to lists Comp ( v i ) and up date Comp ( v i ) for all relev ant no des v i of T . Then, we insert s in to data structures D ( v i ) and M ( v i ). Using the data structure R , we can iden tify the segment s 0 ( v R ) that precedes s in S ( v R ). Then, w e find the p osition of s 0 ( v R ) in Comp ( v R ). W e also find the lea v es v a and v b of T , in whic h the left and the righ t endp oin ts of s must b e stored. The path π = v R , . . . , v a is trav ersed starting at the ro ot no de. Let s 0 ( v i ) b e the segment that precedes s in Comp ( v i ) and let B ( v i ) b e the blo ck that contains s 0 ( v i ). In every no de v i , we insert 8 the iden tifier for s after s 0 ( v i ). W e also up date data structures F ( B ( v i )) and H ( B ( v i )) for the blo c k B ( v i ) that contains s . If the num ber of in terv als in B ( v i ) equals 2 log 3 n , we split the blo c k B ( v i ) into tw o blo cks B 1 ( v i ) and B 2 ( v i ) of equal size. W e assign a new lab el to B 2 ( v i ) and up date the lab els for some blo c ks of Comp ( v i ) in O (log 2 n ) time. W e also ma y hav e to up date O (log ε n ) split-find data structures P f ( v i ). Besides that, O (1) child p oin ters in the parent of v i and O (log ε n ) paren t pointers in the c hildren of v i ma y also b e up dated. W e split the blo ck after Θ(log 3 n ) insertions; hence, an amortized cost of splitting a blo ck is O (1). When s is inserted into Comp ( v i ), w e find the largest element s 0 ( v i − 1 ) ≤ s , such that s 0 ( v i − 1 ) is also stored in Comp ( v i − 1 ). Then, we find the p osition of s 0 ( v i − 1 ) in Comp ( v i − 1 ) and pro ceed in the no de v i − 1 . Let v c b e the low est common ancestor of v a and v b , and let π b b e the path from v c to v b . W e also insert s into Comp ( v j ) for all v j ∈ π b ; no des v j ∈ π b are pro cessed in the same wa y as no des v i ∈ π a During the second stage, w e up date data structures D ( v i ) and M ( v i ) for v i ∈ π a ∪ π b . F or any suc h v i w e already know the blo c k B ∈ Comp ( v i ) that contains s and the p osition of s in B . Hence, a data structure G ( B ) can b e up dated in O (1) time. If s is the only in terv al in B that b elongs to S lr ( v i ) for some l , r , w e insert lab ( B ) into D lr ( v i ). If lab ( B ) is the greatest lab el in D lr ( v i ), w e also up date M ( v i ). An insertion into a data structure D lr ( v i ), v i ∈ π a ∪ π b , takes O (log log n ) time. Updates of all other structures in v i tak e O (1) time. Hence, an insertion tak es O (log n ) time in total. When an in terv al is deleted, w e identify its position in every relev an t no de v i . This can b e done in the same w a y as during the first stage of the insertion pro cedure. Then, we up date the data structures D ( v i ), M ( v i ), and G ( B ( v i )) if necessary . Since a blo c k lab el can b e remov ed from D lr ( v i ) in O (1) time, the total time necessary to delete an in terv al is O (log n/ log log n ). Re-Balancing of the T ree No des. It remains to sho w how the tree can b e rebalanced after up dates, so that the height of T remains O (log n/ log log n ). W e implemen t the base tree T as a w eigh t-balanced B-tree [4] with branching parameter φ and leaf parameter φ for φ = log ε n . W e assume that the constan t ε < 1 / 8. When a segment s is deleted, we simply mark it as deleted. After n/ 2 deletions, we re-build the base tree and all data structures stored in the no des. This can be done in O ( n log n/ log log n ) time. No w w e show ho w insertions can b e handled. W e denote by the weigh t of u the total num ber of elemen ts in the leaf descendants of u . The weigh t n u of u also equals to the num ber of segment iden tifiers in Comp ( u ). Our weigh t-balanced B-tree is organized in such w a y that n u = Θ( φ ` +1 ), where φ = log ε n and ` is the level of a node u . A node is split after Θ( φ ` +1 ) insertions; when a no de u is split in to u 0 and u 00 , the ranges of the other no des in the base tree do not c hange; see [4] for a detailed description of no de splitting. W e will show that all relev ant data structures can b e re-built in O ( n u ) time. Hence, the amortized cost of splitting a no de is O (1). When a segment is inserted, it is inserted into O (log n/ log log n ) no des of the base tree. Hence, the total amortized cost of all splitting op erations caused b y inserting a segmen t s into our data structure is O (log n/ log log n ). It remains to sho w how secondary data structures are up dated when a no de u is split. Let w b e the parent of u . The total num ber of segmen ts in S ( u 0 ) and S ( u 00 ) do es not exceed | S ( u ) | = O ( n u ). Hence, we can construct data structures D ( u 0 ), D ( u 00 ) and lists Comp ( u 0 ), Comp ( u 00 ) with all blo ck data structures in O ( | S ( u ) | ) = O ( n u ) time. W e can find the p ositions of all elemen ts e ∈ Comp ( u 0 ) ∪ Comp ( u 00 ) in Comp ( w ), up date their identifiers in Comp ( w ), and up date all auxiliary data structures in O ( n u ) time. 9 α w u α w u 0 u 00 (a) (b) Figure 3: No de u is split into u 0 and u 00 . Segmen t α is mov ed from S ( u ) to S ( w ) after splitting of a no de u . Some of the interv als stored in S ( u ) can b e mov ed from S ( u ) to S ( w ): if an interv al s ∈ S ( u ) do es not cov er r ng ( u ) but cov ers r ng ( u 0 ) or r ng ( u 00 ), then s must b e stored in S ( w ) after splitting. See Fig. 3 for an example. The total n um b er of elements in Comp ( w ) is Θ( φ ` +2 ) = Θ( n u · φ ); hence, the total n um b er of blocks in Comp ( w ) is o ( n u / log 3 n ). Identifiers of all segmen ts in S ( u ) are already stored in Comp ( w ). W e can up date all block data structures in O (1) time per segmen t. Every up date of the data structure D ( w ) tak es O (log log n ) time. But the total n umber of insertions into D ( w ) do es not exceed the num ber of blo cks in D ( w ). Therefore the total time needed to update D ( w ) is O ( n u log ε − 3 n ) = o ( n u ). Supp ose that u was the k -th child of w . Some segments stored in S lk ( w ) for l < k can b e mo v ed to S l ( k +1) ( w ), and some segmen ts in S kr ( w ) for r > k can b e mov ed to S ( k +1) r ( w ). Since the total n um b er of blo c ks in Comp ( w ) is O ( n u / log 3 n ), all up dates of data structures D ij ( w ) tak e O (( n u / log 3 n ) log log n ) = o ( n u ) time. At most n u segmen ts w ere stored in S lk ( w ) and S kr ( w ) b efore the split of u . Hence, w e can up date all blo ck data structures in O ( n u ) time. Finally , we m ust change the identifiers of segments stored in Comp ( w ) and data structures G ( B ). Recall that an iden tifier indicates in whic h children of w a segment s is stored. Supp ose that a segment s had an identifier r > k in Comp ( w ). Then its iden tifier will b e c hanged to r + 1 after the split of u . The total num b er of segments with incremented identifiers do es not exceed n w = O ( n u · φ ). How ev er, each identifier is stored in O (log log n ) bits. W e can use this fact, and incremen t the v alues of √ log n identifiers in O (1) time using the following lo ok-up table T . There are O ((log n ) √ log n ) different sequences of √ log n identifiers. F or every such sequence α and any j = O (log ε n ), T [ α ][ j ] = α 0 . Here α 0 is the sequence that we obtain if every j 0 > j in the sequence α is replaced with j 0 + 1. Th us the list Comp ( w ) can b e up dated in O ( n w / √ log n ) = O ( n u ) time. Using the same approach, we can also up date data structures F ( B ) and G ( B ) for each blo ck B in O ( | B | / √ log n ) time. Hence, the total time necessary to up date all data structures in w because some iden tifiers m ust b e incremented is O ( n u ). Since all data structures can b e up dated in O ( n u ) time when a no de u is split, the total amortized cost of an insertion is O (log n ). 10 5 Multi-Dimensional Stabbing-Max Queries Our data structure can b e extended to the case of d -dimensional stabbing-max queries for d > 1. In this section w e pro v e the following theorem. Theorem 2 Ther e exists a data structur e that uses O ( n (log n/ log log n ) d − 1 ) sp ac e and answers d -dimensional stabbing-max queries in O ((log n/ log log n ) d ) time. Insertions and deletions ar e supp orte d in O ((log n/ log log n ) d log log n ) and O ((log n/ log log n ) d ) amortize d time r esp e ctively. Let ( d, g )-stabbing problem denote the ( d + g )-dimensional stabbing-max problem for the case when the first d coordinates can assume arbitrary v alues and the last g co ordinates are b ounded b y log ρ n , for ρ ≤ 1 8( g + d ) . First, we show that the data structure of Theorem 1 can b e mo dified to supp ort (1 , g )-stabbing queries for any constant g . Then, w e will show ho w arbitrary d -dimensional queries can b e answered. Throughout this section pr oj i ( s ) denotes the pro jection of a rectangle s on the i -th co ordinate. W e denote by b i ( s ) and e i ( s ) the i -th co ordinates of endp oints in a rectangle s , so that pr oj i ( s ) = [ b i ( s ) , e i ( s )]. A Data Structure for the (1 , g ) -Stabbing Problem. The solution of the (1 , g )-stabbing problem is very similar to our solution of the one-dimensional problem. W e construct the base tree T on the x -co ordinates of all rectangles. T is defined as in section 2, but w e assume that ε ≤ ρ . Sets S ( u ), S lr ( u ), and S ( u ) are defined as in sections 2, 3. W e define S lr [ j 1 , . . . , j g , . . . , j 2 g ]( u ) as the set of rectangles s in S lr ( u ) suc h that b 2 ( s ) = j 1 , . . . , b g +1 ( s ) = j g , e 2 ( s ) = j g +1 , . . . , e g +1 ( s ) = j 2 g . A rectangle iden tifier for a rectangle s stored in a list Comp ( u ) consists of one or t w o tuples with 2 g + 1 comp onen ts. The first comp onent of each tuple is an index j , suc h that s belongs to the j -th c hild of u ; remaining 2 g comp onen ts are the last g co ordinates of the rectangle end- p oin ts. The data structure M ( u ) con tains the maxim um priorit y rectangle in S lr [ j 1 , . . . , j 2 g ]( u ) for eac h l, r, j 1 , . . . , j 2 g . M ( u ) can find for any ( f , h 1 , . . . , h g ) the highest priorit y rectangle in all S lr [ j 1 , . . . , j 2 g ]( u ), such that l ≤ f ≤ r , and j i ≤ h i ≤ j g + i for 1 ≤ i ≤ g . W e can implement M ( u ) as for the one-dimensional data structure. Data structure D ( u ) consists of VEB structures D lr [ j 1 , . . . , j 2 g ]( u ). If a blo c k B of Comp ( u ) con tains a rectangle from S lr [ j 1 , . . . , j 2 g ]( u ), then lab ( B ) is stored in D lr [ j 1 , . . . , j 2 g ]( u ). W e can answ er a query q = ( q x , q 1 , . . . , q g ) by trav ersing the search path π = v 0 , . . . , v R for q x in the base tree T . As in Theorem 1, we start at the leaf no de v 0 and find the maximal rectangle stored in S ( v l ) that is stabb ed b y the query p oint q . The search pro cedure in no des v 1 , . . . , v R is organized in the same wa y as the search pro cedure in section 3: The rectangle s ( v i ) is defined as in section 3. If v i − 1 is the f -th c hild of v i , w e answ er the query ( f , q 1 , . . . , q g ) using the data structure M ( v i ). Then we visit the blo c k B m returned by M ( v i ) and find the last rectangle s m in B m with an iden tifier ( f , b 2 ( s m ) , . . . , b g +1 ( s m ) , e 2 ( s m ) , . . . , e g +1 ( s m )) suc h that b i +1 ( s m ) ≤ q i ≤ e i +1 ( s m ) for 1 ≤ i ≤ g . Finally we compare s m with the rectangle s ( v i − 1 ) b y comparing their p ositions in Comp ( v i ). Thus we can find the p osition of s ( v i ) in Comp ( v i ). When we reach the ro ot v R , s ( v R ) is the highest priorit y segmen t that is stabb ed by q . Up dates of the list Comp ( u ) and all auxiliary data structures are implemen ted as in section 4. Lemma 1 Ther e exists a data structur e that answers (1 , g ) -stabbing queries in O (log n/ log log n ) time and uses O ( n ) sp ac e. Insertions and deletions ar e supp orte d in O (log n ) and O (log n/ log log n ) amortize d time r esp e ctively. A Data Structure for the ( d, g ) -Stabbing Problem. The result for (1 , g )-stabbing can b e extended to ( d, g )-stabbing queries using the following Lemma. 11 Lemma 2 Supp ose that ther e is a O ( n (log n/ log log n ) d − 2 ) sp ac e data structur e D 1 that answers ( d − 1 , g + 1) -stabbing queries in O ((log n/ log log n ) d − 1 ) time; D 1 supp orts insertions and deletions in O ((log n/ log log n ) d − 1 log log n ) and O ((log n/ log log n ) d − 1 ) amortize d time r esp e ctively. Then ther e exists a O ( n (log n/ log log n ) d − 1 ) sp ac e data structur e D 2 that answers ( d, g ) -stabbing queries in O ((log n/ log log n ) d ) time; D 2 supp orts insertions and deletions in amortize d time O ((log n/ log log n ) d log log n ) and O ((log n/ log log n ) d ) r esp e ctively. The main idea is to construct the base tree T on the d -th co ordinates of rectangles and store a data structure for ( d − 1 , g + 1)-stabbing queries in each tree no de. The tree is organized as in section 2 and the first part of this section. Let q d denote the d -th co ordinate of a p oint. Leav es con tain d -th co ordinates of rectangle endp oin ts. A rectangle s is stored in a set S ( u ) for a leaf u if pr oj d ( s ) ∩ rng ( u ) 6 = ∅ and r ng ( u ) 6⊂ pr oj d ( s ). A rectangle s is stored in a set S ( u ) for an in ternal no de u if r ng ( u ) 6⊂ pr oj d ( s ) and r ng ( u i ) ⊂ pr oj d ( s ) for at least one c hild u i of u . S ij ( u ) is the set of all interv als s ∈ S ( u ) suc h that r ng ( u f ) ⊂ proj d ( s ) for a child u f of u if and only if i ≤ f ≤ j . W e store a data structure D ( u ) for ( d − 1 , g + 1)-stabbing queries in each in ternal no de u . F or a rectangle s ∈ S lr ( u ), D ( u ) con tains a rectangle s 0 suc h that pr oj g ( s ) = pr oj g ( s 0 ) for g 6 = d and pr oj d ( s 0 ) = [ l, r ]. In other words, w e replace the d -th co ordinates of s ’s endp oin ts with l and r . A query q is answ ered by trav ersing the searc h path for q . F or a leaf no de v 0 , we examine all rectangles in S ( v 0 ) and find the highest priority rectangle in S ( v 0 ). In an internal no de v i , i ≥ 1, w e answer the query q ( v i ) = ( q 1 , . . . , q d − 1 , f , q d +1 , . . . , q d + g ) using the data structure D ( v i ). The query q ( v i ) is obtained from q by replacing the d -th co ordinate with an index f , such that v i − 1 is the f -th c hild of v i . When a no de v i is visited, our pro cedure finds the highest priority rectangle s ( v i ) that is stored in S ( v i ) and is stabb ed b y q . All rectangles that are stabb ed by q are stored in some S ( v i ). Hence, the highest priorit y rectangle stabb ed by q is the maximum rectangle among all s ( v i ). Since our pro cedure sp ends O ((log n/ log log n ) d − 1 ) time in eac h no de, the total query time is O ((log n/ log log n ) d ). When a rectangle s is inserted or deleted, we up date O (log n/ log log n ) data structures D ( u ) in which s is stored. Hence, deletions and insertions are supp orted in O ((log n/ log log n ) d ) and ((log n/ log log n ) d log log n ) time resp ectively . W e can re-balance the base tree using a pro cedure that is similar to the pro cedure describ ed in section 4. Pro of of Theorem 2. Theorem 2 follows easily from Lemmas 1 and 2. By Lemma 1, there exists a linear space data structure that answers (1 , d − 1)-stabbing queries in O (log n/ log log n ) time. W e obtain the main result for d -dimensional stabbing-max queries b y applying the result of Lemma 2 to the data structure for (1 , d − 1)-stabbing queries. 6 Stabbing-Sum Queries W e can also mo dify our data structure so that it supp orts stabbing-sum queries: coun t the num b er of in terv als stabb ed by a query p oint q . Theorem 3 Ther e exists a line ar sp ac e data structur e that answers ortho gonal stabbing-sum queries in O (log n/ log log n ) time. This data structur e supp orts insertions and deletions in O (log n ) and O (log n/ log log n ) amortize d time r esp e ctively. The only difference with the pro of of Theorem 1 is that we store data structures for coun ting in terv als instead of M ( u ). W e maintain a data structure X ( u ) in each in ternal no de u . F or a query 12 index f , X ( u ) rep orts in O (1) time the total n um b er of in terv als in ∪ l ≤ f ≤ r S lr ( u ). In ev ery leaf node u l , we maintain a data structure Z ( u l ) that supp orts stabbing sum queries on S ( u l ) and up dates in O (log log n ) time. As ab ov e, let π = v 0 . . . v R denote the search path for a query p oint q . In every no de v i ∈ π , i ≥ 1, we count the n um b er n ( v i ) of interv als in ∪ l ≤ f ≤ r S lr ( u ) using X ( v i ); the index f is chosen so that v i − 1 is the f -th child of v i . W e also compute the num ber n ( v 0 ) of interv als that b elong to S ( v 0 ) and are stabb ed by q using Z ( v 0 ). An in terv al s is stabb ed b y q either if s is stored in S ( v i ), i ≥ 1, and r ng ( v i − 1 ) ⊂ s or if s is stored in S ( v 0 ) and s is stabb ed by q . Hence, q stabs P v i ∈ π n ( v i ) in terv als. Eac h n ( v i ), i ≥ 1, can b e found in O (1) time and n ( v 0 ) can b e found in O (log log n ) time. Hence, a query can b e answ ered in O (log n/ log log n ) time. No w we turn to the description of the data structure X ( u ). F ollowing the idea of [17], we store information ab out the recent up dates in a word B ; the array A reflects the state of the structure b efore recent up dates. A is a static arra y that is re-built after log 2 ε n up dates of X ( u ). When w e construct A , we set A [ f ] = P l ≤ f ≤ r | S lr ( u ) | . The word B con tains one in teger v alue m ( l, r ) for eac h pair l ≤ r ( m ( l, r ) can also b e negative, but the absolute v alue of each m ( l, r ) is b ounded by O (log ε n )). When a segment is inserted into (deleted from) S lr ( u ), we increment (decrement) the v alue of m ( l, r ) b y 1. W e can find P l ≤ f ≤ r m ( l, r ) in O (1) time using a lo ok-up table. After log ε n up dates we rebuild the array A and set all m ( l , r ) = 0. The amortized cost of rebuilding A is O (1). The total num b er of segmen ts in ∪ l ≤ f ≤ r S lr ( u ) equals to A [ f ] + P l ≤ f ≤ r m ( l, r ). Hence, a query to X ( u ) is answ ered in O (1) time. W e implement A in such w a y that eac h en try A [ i ] uses O (log | S ( u ) | ) bits. Thus each data structure X ( u ) uses O (log ε n log | S ( u ) | ) bits and all X ( u ), u ∈ T , use O ( n log n ) bits in total. It remains to describ e the data structure Z ( u ). Let E ( u ) b e the set that contains endp oin ts of all in terv als in S ( u ). Since u is a leaf no de, S ( u ) con tains O (log 2 ε n ) elemen ts. Hence, it takes O (log log n ) time to find the rank r ( q ) of q in E ( u ). F or eac h 1 ≤ i ≤ | E | , C [ i ] equals to the n um b er of interv als that are stabb ed by a p oin t q with rank r ( q ) = i . The array C enables us to count in terv als stabb ed b y q in O (1) time if the rank of q in E ( u ) is kno wn. Since | E | = O (log ε n ) and C [ i ] = O (log ε n ), the array C uses O (log ε n log log n ) bits of memory . When a set S ( u ) is up dated, w e can up date C in O (1) time using a lo ok-up table. Th us Z ( u ) uses linear space and supp orts b oth queries and up dates in O (log log n ) time. References [1] P . K. Agarw al, L. Arge, J. Y ang, and K. Yi, I/O Efficient Structur es for Ortho gonal R ange Max and Stabbing Max Queries , Pro c. ESA 2003, 7-18. [2] P . K. Agarw al, L. Arge, K. Yi, A n Optimal Dynamic Interval Stabbing-Max Data Structur e? , Pro c. SOD A 2005, 803-812. [3] S. Alstrup, T. Husfeldt, T Rauhe, Marke d Anc estor Pr oblems , Pro c. FOCS 1998, 534-544. [4] L. Arge, J. S. Vitter, Optimal External Memory Interval Management , SIAM J. Comput. 32(6), 1488-1508 (2003). [5] G. E. Blello c h, Sp ac e-Efficient Dynamic Ortho gonal Point L o c ation, Se gment Interse ction, and R ange R ep orting , Pro c. SODA 2008, 894-903. 13 [6] B. Chazelle, A F unctional Appr o ach to Data Structur es and its Use in Multidimensional Se ar ching , SIAM J. on Computing, 17, 427-462 (1988). [7] H. Edelsbrunner, A New App r o ach to R e ctangle Interse ctions , part I, In t. J. Computer Math- ematics, 13, 209-219 (1983). [8] P . v an Emde Boas, R. Kaas, E. Zijlstra, Design and Implementation of an Efficient Priority Queue , Mathematical Systems Theory 10, 99-127 (1977). [9] P . Gupta and N. McKeown. Dynamic Algorithms with Worst-Case Performanc e for Packet Classific ation , Pro c. IFIP Netw orking 2000, 528- 539. [10] P . Gupta and N. McKeown. Algorithms for Packet Classific ation , IEEE Net w ork, 15(2), 24-32 (2001). [11] A. F eldmann, S. Muth ukrishnan, T r ade offs for Packet Classific ation , Pro c. INFOCOM 2000, 1193-1202. [12] M. L. F redman, D. E. Willard, T r ans-Dichotomous Algorithms for Minimum Sp anning T r e es and Shortest Paths , J. Comput. Syst. Sci. 48(3), 533-551 (1994). [13] H. Imai and T. Asano, Dynamic Ortho gonal Se gment Interse ction Se ar ch , Journal of Algo- rithms 8(1), 1-18 (1987). [14] A. Itai, A. G. Konheim, M. Rodeh, A Sp arse T able Implementation of Priority Queues , Pro c. 8th ICALP 1981,417-431. [15] H. Kaplan, E. Molad, R. E. T arjan, Dynamic R e ctangular Interse ction with Priorities , Pro c. STOC 2003, 639-648. [16] Y. Nekrich, Ortho gonal R ange Se ar ching in Line ar and Almost-Line ar Sp ac e , Comput. Geom. 42(4), 342-351 (2009). [17] M. Pˇ atra ¸ scu, E. D. Demaine, Tight Bounds for the Partial-Sums Pr oblem , Pro c. 15th SODA 2004, 20-29. [18] S. Sahni and K. Kim, O (log n ) Dynamic Packet R outing , Pro c. IEEE Symp osium on Comput- ers and Comm unications 2002, 443-448. [19] S. Sahni, K. Kim, and H. Lu. Data Structur es for One-Dimensional Packet Classific ation Using Most Sp e cific Rule Matching , Pro c. ISP AN 2002, 3-14. [20] R. E. T arjan, A Class of Algorithms which R e quir e Nonline ar Time to Maintain Disjoint Sets , J. Comput. Syst. Sci. 18(2), 110-127 (1979). [21] M. Thorup, Undir e cte d Single-Sour c e Shortest Paths with Positive Inte ger Weights in Line ar Time , J. A CM 46(3), 362-394 (1999). [22] M. Thorup, Sp ac e Efficient Dynamic Stabbing with F ast Queries , Pro c. STOC 2003, 649-658. 14 [23] D. E. Willard, A Density Contr ol Algorithm for Doing Insertions and Deletions in a Se- quential ly Or der e d File in Go o d Worst-Case Time , Information and Computation 97, 150-204 (1992). [24] J. Y ang, J. Widom, Incr emental Computation and Maintenanc e of T emp or al A ggr e gates , Pro c. IEEE In tl. Conf. on Data Engineering 2001, 51-60. 15 App endix A. Auxiliary Data Structures Using bitwise op erations and table lo ok-ups, w e can implemen t the data structure M ( u ) and the blo c k data structures so that queries are supp orted in constant time. Data Structure M ( u ) . Let M ( u ) b e the set of all interv al priorities stored in M ( u ). Recall that M ( u ) contains an element max ij for each set S ij ( u ), where max ij is the highest priorit y in terv al (or its blo ck lab el) stored in S ij ( u ). F or simplicity , w e assume that max ij = −∞ if S ij = ∅ . Let the rank of x in M ( u ) b e defined as rank ( x, M ( u )) = |{ e ∈ M ( u ) | e ≤ x }| . Let M 0 ( u ) be the set in whic h every element of M ( u ) is replaced with its rank in M ( u ). That is, for eac h max ij stored in M ( u ) w e store max 0 ij = rank (max ij , M ( u )) in the set M 0 ( u ). Eac h of O (log 1 / 4 n ) elemen ts in M 0 ( u ) is bounded by O (log 1 / 4 n ). Hence, w e can store M 0 ( u ) in one bit sequence W ; W consists of O (log 1 / 4 n log log n ) bits and fits in to a machine w ord. W e can store a table Tbl 1 with an en try for each p ossible v alue of W and for each f . The entry Tbl [ W ][ f ] con tains the pair < l, r > , such that max 0 lr is the highest v alue in the set { max 0 ij | i ≤ f ≤ j } . Ob viously , max ab < max cd if and only if max 0 ab < max 0 cd . Therefore a query f can be answered b y lo oking up the v alue < l , r > = Tbl [ W ][ f ] for W = M 0 ( u ) and returning the elemen t max lr . When M ( u ) is up dated, the v alue of some max ij is c hanged. W e store all elements of M ( u ) in an atomic heap [12, 21] that supp orts predecessor queries and up dates in O (1) time. Hence, the new rank of max ij in M ( u ) can b e found in O (1) time. If the rank of max ij has changed, the ranks of all other elemen ts in M ( u ) also change. F ortunately , max 0 ij can assume only O (log 1 / 4 n ) v alues. There are O (log 1 / 4 n ) elements max 0 ij in a set M 0 ( u ), and there are 2 O (log 1 / 4 n ) = o ( n ) differen t sets M 0 ( u ). Besides that, each W = M 0 ( u ) fits into one word. Hence, w e can update the set M 0 ( u ) using a lo ok-up in a table Tbl 1 . Supp ose that the rank of the f -th element in a set M 0 ( u ) is c hanged to r . Then the new set M 0 ( u ) is stored in an entry Tbl 1 [ W ][ f ][ r ] of Tbl 1 ; here W is the bit sequence that corresp onds to the old set M 0 ( u ). Th us an up date of M ( u ) c an b e implemen ted in O (1) time. W e need only one instance of tables Tbl and Tbl 1 for all no des u of the base tree. Both tables use o ( n ) space and can b e initialized in o ( n ) time. Data Structure F ( B ) . The data structure F ( B ) for a blo ck B ∈ Comp ( u ) is implemented as a B-tree T F . Every leaf of T F con tains Θ( ρ ) identifiers and each internal no de has degree Θ( ρ ) for ρ = √ log n . Recall that eac h iden tifier consists of at most tw o indices i 1 , i 2 suc h that the corresp onding in terv al is stored in the i 1 -th and i 2 -th children of the no de u in the base tree. All iden tifiers stored in a leaf no de can b e pack ed into O ( ρ log log n ) bits. In every internal no de ν of T F , we store the bit sequence W ( ν ). F or every c hild ν i and for every p ossible v alue of j , W ( ν ) con tains the total num ber of indices j in the i -th child ν i of ν ; W ( ν ) consists of O ( ρ log log n ) bits. Using a lo ok-up table, we can coun t for any W ( ν ) and for an y i the total n um b er of elemen ts stored in the children ν 1 , . . . , ν i − 1 of ν . F or any W ( ν ) and i , we can also count the total n um b er of indices j in the children ν 1 , . . . , ν i − 1 of ν . F or any k ≤ 2 log 3 n and any W ( ν ), j , we can find the largest i suc h that the total num ber of indices j in ν 1 . . . , ν i do es not exceed k . Look-up tables that supp ort suc h queries use o ( n ) space and can b e initialized in o ( n ) time. W e need only one instance of each table for all blo c ks B and all F ( B ). All queries and up dates of a data structure F ( B ) can be pro cessed b y trav ersing a path in T F . Using the ab ov e describ ed lo ok-up-tables, w e spend only constan t time in each no de of T F ; hence, queries and up dates are supp orted in O (1) time. Details will b e given in the full version of this pap er. Data structures G ( B ) and H ( B ) can b e implemented in a similar wa y . 16

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment