Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Orthogonal Range Searching Advanced Data Structures Computation and Reasoning Laboratory Graduate Course - Spring 2007 April 16, 2007 Outline 1 Introduction 2 1-Dimensional Range Searching 3 Kd-Trees 4 Range Trees 5 Fractional Cascading Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 2 / 44 Outline 1 Introduction 2 1-Dimensional Range Searching 3 Kd-Trees 4 Range Trees 5 Fractional Cascading Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 3 / 44 Querying a Database Do databases have something to do with geometry? Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 4 / 44 Querying a Database Do databases have something to do with geometry? Queries in a database can be interpreted geometrically. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 4 / 44 Querying a Database Do databases have something to do with geometry? Queries in a database can be interpreted geometrically. Transform records in a database into points in a multi-dimensional space. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 4 / 44 Querying a Database Do databases have something to do with geometry? Queries in a database can be interpreted geometrically. Transform records in a database into points in a multi-dimensional space. Transform queries about the records into queries on the set of points. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 4 / 44 A typical query interpreted geometrically salary 4000 G. Ometer born: Aug 19, 1954 salary: $3200 3000 19500000 Advanced Data Structures (Spring 2007) 19559999 Orthogonal Range Searching date of birth CoReLab Graduate Course 5 / 44 A query in 3 dimensions salary 4000 3000 chlidren 4 2 19500000 Advanced Data Structures (Spring 2007) 19559999 Orthogonal Range Searching date of birth CoReLab Graduate Course 6 / 44 The geometric approach We are interested in answering queries on d fields of the records in our database. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 7 / 44 The geometric approach We are interested in answering queries on d fields of the records in our database. Transform the records to points in d-dimensional space. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 7 / 44 The geometric approach We are interested in answering queries on d fields of the records in our database. Transform the records to points in d-dimensional space. The transformed query asks for all points inside a d-dimensional axis-parallel box. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 7 / 44 The geometric approach We are interested in answering queries on d fields of the records in our database. Transform the records to points in d-dimensional space. The transformed query asks for all points inside a d-dimensional axis-parallel box. Such a query is called ‘‘rectangular’’ or ‘‘orthogonal’’ range query. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 7 / 44 The geometric approach We are interested in answering queries on d fields of the records in our database. Transform the records to points in d-dimensional space. The transformed query asks for all points inside a d-dimensional axis-parallel box. Such a query is called ‘‘rectangular’’ or ‘‘orthogonal’’ range query. We are going to present data structures for such queries. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 7 / 44 Outline 1 Introduction 2 1-Dimensional Range Searching 3 Kd-Trees 4 Range Trees 5 Fractional Cascading Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 8 / 44 The problem Data A set of points P = {p1 , p2 , . . . , pn } in 1-dimensional space (a set of real numbers). Query Which points lie inside a ‘‘1-dimensional query rectangle’’? (i.e. an interval [x : x 0 ]) Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 9 / 44 Efficient Data Structures Arrays Solve the problem, but do not generalize, do not allow efficient updates. Balanced Binary Search Trees (BBST) The leaves of T store the points of P, internal nodes store splitting values that guide the search. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 10 / 44 Balanced Binary Search Trees xv v xi ≤ xv pi Advanced Data Structures (Spring 2007) xv < xj pj Orthogonal Range Searching CoReLab Graduate Course 11 / 44 A search with the interval [18 : 77] 49 23 80 10 37 3 3 19 10 19 30 23 30 62 49 37 59 59 70 62 70 89 80 100 100 105 µ0 µ Advanced Data Structures (Spring 2007) 89 Orthogonal Range Searching CoReLab Graduate Course 12 / 44 A search with the interval [x , x 0 ] Search for x and x 0 in T . The search ends to leaves µ and µ0 . Report all the points stored at leaves between µ and µ0 plus, possibly, the points stored at µ and µ0 . Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 13 / 44 A search with the interval [x , x 0 ] Search for x and x 0 in T . The search ends to leaves µ and µ0 . Report all the points stored at leaves between µ and µ0 plus, possibly, the points stored at µ and µ0 . Remark The leaves to be reported are the ones of subtrees that are rooted at nodes whose parents are on the search paths to µ and µ0 . Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 13 / 44 The selected subtrees root(T ) vsplit µ0 µ Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 14 / 44 Algorithms 1D-RangeQuery(T , [x : x 0 ]) FindSplitNode(T , x , x 0 ) v ← root (T ) while v is not a leaf and (x 0 ≤ xv or x > xv ) do if x 0 ≤ xv then v ← lc (v) else v ← rc (v) return v vsplit ← FindSplitNode(T , x , x 0 ) if vsplit is a leaf then check if xvsplit must be reported else {follow the path to x} v ← lc (vsplit ) while v is not a leaf do if x ≤ xv then ReportSubtree(rc (v)) {subtrees right of path} v ← lc (v) else v ← rc (v) check if xv must be reported ... Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 15 / 44 Correctness and Performance Any reported point lies in the query range. Any point in the range is reported. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 16 / 44 Correctness and Performance Any reported point lies in the query range. Any point in the range is reported. O (n ) storage. O (n log n ) preprocessing. Θ(n ) worst case case query cost. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 16 / 44 Correctness and Performance Any reported point lies in the query range. Any point in the range is reported. O (n ) storage. O (n log n ) preprocessing. Θ(n ) worst case case query cost. O (k + log n ) output sensitive query cost: O (k ) to report the points plus O (log n ) to follow the paths to x, x 0 . Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 16 / 44 Outline 1 Introduction 2 1-Dimensional Range Searching 3 Kd-Trees 4 Range Trees 5 Fractional Cascading Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 17 / 44 The problem Data A set of points P = {p1 , p2 , . . . , pn } in the plane. Query Which points lie inside a query rectangle [x : x 0 ] × [y : y0 ]? Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 18 / 44 The problem Data A set of points P = {p1 , p2 , . . . , pn } in the plane. Query Which points lie inside a query rectangle [x : x 0 ] × [y : y0 ]? Remark A point p = (px , py ) lies inside this rectangle iff px ∈ [x , x 0 ] and py ∈ [y, y0 ]. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 18 / 44 The way the plane is subdivided l5 p1 p2 l1 l7 p8 p3 l8 p6 l9 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) l6 Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided p1 p2 l1 p8 p3 p6 p7 p5 p9 p4 p10 Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided p1 p2 l1 p8 p3 p6 p7 p5 p9 l2 p4 p10 Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided p1 p2 l1 p8 p3 p6 p7 p5 p9 l3 l2 p4 p10 Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided p1 p2 l1 p8 p3 p6 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided l5 p1 p2 l1 p8 p3 p6 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided l5 p1 p2 l1 p8 p3 p6 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) l6 Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided l5 p1 p2 l1 l7 p8 p3 p6 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) l6 Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided l5 p1 p2 l1 l7 p8 p3 p6 l8 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) l6 Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The way the plane is subdivided l5 p1 p2 l1 l7 p8 p3 p6 l8 l9 p7 p5 p9 l3 l2 p4 p10 l4 Advanced Data Structures (Spring 2007) l6 Orthogonal Range Searching CoReLab Graduate Course 19 / 44 The corresponding binary tree l1 l2 l3 l4 p5 ll55 p4 pp22 p10 l8 pp33 Advanced Data Structures (Spring 2007) l6 ll57 p9 pp11 Orthogonal Range Searching pp27 l9 pp63 pp18 CoReLab Graduate Course 20 / 44 Algorithm BuildKdTree(P , depth ) if P contains only one point then return a leaf storing this point else if depth is even then split P with vertical l through median x-coord of points in P P1 ← the set of points left of l or on l P2 ← the set of points right of l else split P with horizontal l through median y-coord of points in P P1 ← the set of points below l or on l P2 ← the set of points above l vleft ← BuidKdTree(P1 , depth + 1) vright ← BuidKdTree(P2 , depth + 1) create a node v storing l lc (v) → vleft rc (v) → vright return v Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 21 / 44 Algorithm BuildKdTree(P , depth ) if P contains only one point then return a leaf storing this point else if depth is even then split P with vertical l through median x-coord of points in P P1 ← the set of points left of l or on l P2 ← the set of points right of l else split P with horizontal l through median y-coord of points in P P1 ← the set of points below l or on l P2 ← the set of points above l vleft ← BuidKdTree(P1 , depth + 1) vright ← BuidKdTree(P2 , depth + 1) create a node v storing l lc (v) → vleft rc (v) → vright return v Remarks We should split at the n -th 2 smallest coordinate. Preprocessing involves sorting both on x- and y-coordinate. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 21 / 44 Building time and storage The building time satisfies the recurrence: T (n ) = O (1) O (n ) + 2T ( n2 ) if n = 1 if n > 1 T (n ) = O (n log n ) which subsums the preprocessing time. O (n ) storage: each leaf stores a distinct point of P. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 22 / 44 Nodes in a kd-tree and regions in the plane l1 l1 l2 l2 l3 v l3 region(v) Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 23 / 44 Regions and the query algorithm Internal nodes of a Kd-tree correspond to rectangular regions of the plane which can be unbounded on one or more sides. Such regions are bounded by splitting lines stored at ancestors of the internal nodes. region (root (T )) is the whole plane. A point is stored in a subtree rooted at a node v iff it lies in region (v). We search the subtree rooted at v only if the query rectangle intersects region (v). Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 24 / 44 A query on a kd-tree l5 p1 p2 l1 l7 p8 l1 p3 p6 l8 l2 l9 p7 p5 l4 p9 l3 l2 p4 p5 ll55 p4 Advanced Data Structures (Spring 2007) p2 l6 p10 l8 p3 p10 l4 l3 pp11 ll57 p9 pp27 l9 pp63 pp18 l6 Orthogonal Range Searching CoReLab Graduate Course 25 / 44 Algorithm SearchKdTree(v, R ) if v is a leaf then report the point stored at v if it lies in R else if region (lc (v)) is fully contained in R then ReportSubtree(lc (v)) else if region (lc (v)) intersects R then SearchKdTree(lc (v), R ) if region (rc (v)) is fully contained in R then ReportSubtree(rc (v)) else if region (rc (v)) intersects R then SearchKdTree(rc (v), R ) Advanced Data Structures (Spring 2007) Works for any query range R (e.g. triangles). O (k ), in order to report k points. How many other nodes are visited? For these nodes v, the query range intersects region (v). Orthogonal Range Searching CoReLab Graduate Course 26 / 44 Query time analysis Any vertical line intersects region (lc (root (T ))) or region (rc (root (T ))) but not both. If a vertical line intersects region (lc (root (T ))) it will always intersect the regions corresponding to both children of lc (root (T )). Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 27 / 44 Query time analysis The number of intersected regions in a kd-tree storing n points, satisfies the recurrence: Q (n ) = O (1) 2 + 2Q ( n4 ) √ if n = 1 if n > 1 √ Q (n ) = O ( n ). The total query time is O ( n + k ) The analysis is rather pessimistic: In many practical situations the query range is small and will intersect much fewer regions. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 28 / 44 Kd-trees in higher-dimensional spaces Kd-trees can be also used for point sets in 3- or higher-dimensional spaces. Assume the dimension d to be a constant: O (d · n ) storage. O (d · n log n ) construction time. 1 O (n 1− d + k ) query time. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 29 / 44 Outline 1 Introduction 2 1-Dimensional Range Searching 3 Kd-Trees 4 Range Trees 5 Fractional Cascading Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 30 / 44 The Range Tree approach 2D range queries are two 1D range queries one on x − and one on y−coordinate. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 31 / 44 The Range Tree approach 2D range queries are two 1D range queries one on x − and one on y−coordinate. Find first the points whose x −coordinate lies in [x : x 0 ] and worry about the y−coordinate later. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 31 / 44 The Range Tree approach 2D range queries are two 1D range queries one on x − and one on y−coordinate. Find first the points whose x −coordinate lies in [x : x 0 ] and worry about the y−coordinate later. During the 1D range query a logarithmic number of subtrees is selected. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 31 / 44 The Range Tree approach 2D range queries are two 1D range queries one on x − and one on y−coordinate. Find first the points whose x −coordinate lies in [x : x 0 ] and worry about the y−coordinate later. During the 1D range query a logarithmic number of subtrees is selected. The leaves of these subtrees contain exactly the points whose x −coordinate lies in [x : x 0 ]. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 31 / 44 The Range Tree approach Canonical Subset of a node v The subset of points P (v) of P stored in the leaves of the subtree rooted at v. P (root (T )) = P Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 32 / 44 The Range Tree approach Canonical Subset of a node v The subset of points P (v) of P stored in the leaves of the subtree rooted at v. P (root (T )) = P The subset of points whose x −coordinate lies in the query range is a disjoint union of O (log n ) canonical subsets. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 32 / 44 The Range Tree approach Canonical Subset of a node v The subset of points P (v) of P stored in the leaves of the subtree rooted at v. P (root (T )) = P The subset of points whose x −coordinate lies in the query range is a disjoint union of O (log n ) canonical subsets. We are not interested in all the points in such subsets. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 32 / 44 The Range Tree approach Canonical Subset of a node v The subset of points P (v) of P stored in the leaves of the subtree rooted at v. P (root (T )) = P The subset of points whose x −coordinate lies in the query range is a disjoint union of O (log n ) canonical subsets. We are not interested in all the points in such subsets. Report the ones whose y−coordinate lies in [y : y0 ]: This is another 1D query. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 32 / 44 A 2-dimensional Range Tree T binary search tree on x-coordinates Tassoc (v) binary search tree on y-coordinates v P (v) P (v) Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 33 / 44 Algorithm Build2DRangeTree(P ) Build a BST Tassoc on the set Py Store the points of P at the leaves of Tassoc if P contains only one point then Create a leaf v storing this point Associate Tassoc with v else Split P into Pleft and Pright through xmid vleft ← Build2DRangeTree(Pleft ) vright ← Build2DRangeTree(Pright ) create a node v storing xmid lc (v) ← vleft rc (v) ← vright Associate Tassoc with v return v Advanced Data Structures (Spring 2007) Preprocessing involves maintaining two lists of points. One sorted on x −coordinate and one sorted on y−coordinate. The time spend at a node in the main tree is linear in the size of its canonical subset. Orthogonal Range Searching CoReLab Graduate Course 34 / 44 Range Tree storage p p p Advanced Data Structures (Spring 2007) Orthogonal Range Searching p CoReLab Graduate Course 35 / 44 Storage and costruction time Each point is stored only once at a given depth. The total depth is O (log n ): the amount of storage is O (n log n ). Since the time spend at a node in the main tree is linear in the size of its canonical subset the total construction time is the same as the amount of storage. Presorting is O (n log n ). Total construction time is O (n log n ). Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 36 / 44 Algorithm 2DRangeQuery(T , [x : x 0 ] × [y : y0 ]) vsplit ← FindSplitNode(T , x , x 0 ) if vsplit is a leaf then check if xvsplit must be reported else {follow the path to x} v ← lc (vsplit ) while v is not a leaf do if x ≤ xv then 1DRangeQuery(Tassoc (rc (v)), [y : y0 ]) v ← lc (v) else v ← rc (v) check if xv must be reported ... Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 37 / 44 Query time analysis The time spend to report the points whose y−coordinate lie in the range [y : y0 ] is O (log n + kv ) where kv is the number of points reported in this call. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 38 / 44 Query time analysis The time spend to report the points whose y−coordinate lie in the range [y : y0 ] is O (log n + kv ) where kv is the number of points reported in this call. Q (n ) = visited. P v O ((log n ) + kv ) where the summation is over all nodes Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 38 / 44 Query time analysis The time spend to report the points whose y−coordinate lie in the range [y : y0 ] is O (log n + kv ) where kv is the number of points reported in this call. Q (n ) = visited. P v O ((log n ) + kv ) where the summation is over all nodes P points. The search paths v kv = k, the total number of reported P of x and x 0 have length O (log n ): O ( log n ) = O (log2 n ). v Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 38 / 44 Query time analysis The time spend to report the points whose y−coordinate lie in the range [y : y0 ] is O (log n + kv ) where kv is the number of points reported in this call. Q (n ) = visited. P v O ((log n ) + kv ) where the summation is over all nodes P points. The search paths v kv = k, the total number of reported P of x and x 0 have length O (log n ): O ( log n ) = O (log2 n ). v Q (n ) = O (log2 n + k ). Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 38 / 44 Higher-Dimensional Range Trees Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 39 / 44 Higher-Dimensional Range Trees P is a set on n points in d −dimensional space (d ≥ 2): O (n logd −1 n ) storage, O (n logd −1 n ) construction time, O (logd n + k ) query time. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 40 / 44 Outline 1 Introduction 2 1-Dimensional Range Searching 3 Kd-Trees 4 Range Trees 5 Fractional Cascading Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 41 / 44 The idea of Fractional Cascading S1 , S2 are two set of objects with real number keys. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 42 / 44 The idea of Fractional Cascading S1 , S2 are two set of objects with real number keys. The problem is to report all objects in S1 and S2 whose keys lie in [y : y0 ]. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 42 / 44 The idea of Fractional Cascading S1 , S2 are two set of objects with real number keys. The problem is to report all objects in S1 and S2 whose keys lie in [y : y0 ]. The keys are in sorted order in arrays A1 and A2 . Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 42 / 44 The idea of Fractional Cascading S1 , S2 are two set of objects with real number keys. The problem is to report all objects in S1 and S2 whose keys lie in [y : y0 ]. The keys are in sorted order in arrays A1 and A2 . Solution: two binary searches in A1 and A2 . Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 42 / 44 The idea of Fractional Cascading S1 , S2 are two set of objects with real number keys. The problem is to report all objects in S1 and S2 whose keys lie in [y : y0 ]. The keys are in sorted order in arrays A1 and A2 . Solution: two binary searches in A1 and A2 . If S2 ⊆ S1 we can avoid the binary search in A2 . Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 42 / 44 The idea of Fractional Cascading S1 , S2 are two set of objects with real number keys. The problem is to report all objects in S1 and S2 whose keys lie in [y : y0 ]. The keys are in sorted order in arrays A1 and A2 . Solution: two binary searches in A1 and A2 . If S2 ⊆ S1 we can avoid the binary search in A2 . A1 3 10 19 23 30 37 59 62 70 80 100 105 A2 10 19 30 62 70 80 100 Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 42 / 44 A Layered Range Tree 17 8 52 5 15 2 7 2 5 12 7 8 12 33 17 15 58 21 21 41 33 41 58 67 52 67 93 3 10 19 23 30 37 49 59 62 70 80 89 95 99 3 10 19 37 62 80 99 3 62 99 10 19 37 80 19 80 19 80 Advanced Data Structures (Spring 2007) 10 37 10 23 30 49 59 70 89 95 37 3 99 3 62 99 23 30 49 95 30 49 49 30 59 70 89 23 95 95 Orthogonal Range Searching 23 59 70 89 89 70 CoReLab Graduate Course 43 / 44 A query in a Layered Range Tree The query range is [x : x 0 ] × [y : y0 ]. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 44 / 44 A query in a Layered Range Tree The query range is [x : x 0 ] × [y : y0 ]. At vsplit find the entry in A(vsplit ) whose y−coordinate is larger than or equal to y in O (log n ) time. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 44 / 44 A query in a Layered Range Tree The query range is [x : x 0 ] × [y : y0 ]. At vsplit find the entry in A(vsplit ) whose y−coordinate is larger than or equal to y in O (log n ) time. For all O (log n ) nodes on the paths to x and x 0 maintain pointers to the entries in A whose y−coordinate is larger than or equal to y in O (1) time. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 44 / 44 A query in a Layered Range Tree The query range is [x : x 0 ] × [y : y0 ]. At vsplit find the entry in A(vsplit ) whose y−coordinate is larger than or equal to y in O (log n ) time. For all O (log n ) nodes on the paths to x and x 0 maintain pointers to the entries in A whose y−coordinate is larger than or equal to y in O (1) time. Report the points of A(v) in O (1 + kv ) time, kv is the number of reported points at node v. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 44 / 44 A query in a Layered Range Tree The query range is [x : x 0 ] × [y : y0 ]. At vsplit find the entry in A(vsplit ) whose y−coordinate is larger than or equal to y in O (log n ) time. For all O (log n ) nodes on the paths to x and x 0 maintain pointers to the entries in A whose y−coordinate is larger than or equal to y in O (1) time. Report the points of A(v) in O (1 + kv ) time, kv is the number of reported points at node v. Total query time becomes O (log n + k ). Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 44 / 44 A query in a Layered Range Tree The query range is [x : x 0 ] × [y : y0 ]. At vsplit find the entry in A(vsplit ) whose y−coordinate is larger than or equal to y in O (log n ) time. For all O (log n ) nodes on the paths to x and x 0 maintain pointers to the entries in A whose y−coordinate is larger than or equal to y in O (1) time. Report the points of A(v) in O (1 + kv ) time, kv is the number of reported points at node v. Total query time becomes O (log n + k ). Fractional cascading also imporves the query time of higher-dimensional range trees by a logarithmic factor. Advanced Data Structures (Spring 2007) Orthogonal Range Searching CoReLab Graduate Course 44 / 44