1 / 18

Geometric Data Structures

Geometric Data Structures. Reading: Chapter 10 of the Textbook Driving Applications Windowing Queries Related Application Query Image Database. Windowing Queries.

gutierrezm
Download Presentation

Geometric Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Geometric Data Structures • Reading: Chapter 10 of the Textbook • Driving Applications • Windowing Queries • Related Application • Query Image Database M. C. Lin

  2. Windowing Queries • Given a rectangular region (2D or 3D), or a window, the algorithm must determine the part of the database that lie in the window and report them. Data are normally not points, but line segments, polygons, etc. • 2D Windowing: navigation using a map or an electronic GIS; circuit-board layout, etc. • 3D Windowing: view frustrum culling; viewing a complex CAD/CAM model by zooming in to a small portion, etc. M. C. Lin

  3. Orthogonal Window Queries • Let S be a set of n axis-parallel line segments. A query asks for the segments intersecting a 2D query window, W:=[x:x’]x[y:y’] • Most cases, the segment has at least one point inside of W. We can find such segments by performing a range query with W in the set of 2n endpoints of the segments in S, by using a 2D range tree T. 2D range tree can answer a range query in O(log2n + k) time; query time can be improved to O(logn + k) by fractional cascading. • Find segments that intersect W twice either at the left and right edges or top and bottom edges. This reduces to finding horiz. (v) segments intersecting a vert. (h) line. M. C. Lin

  4. Classification of Segments w.r.t. xmid • An interval [x:x’] contains l := (x=qx) iff x  qx x’ • We can classify a set of segments w.r.t to xmid : • Imid: those containingxmid • Ileft: those complete lie to the left& cannot intersectl • Iright: those complete lie to the right& cannot intersectl • Check Imid to find intersecting segments with l • Store the intervals in 2 sorted lists: increasing left endpoints and decreasing right endpoints • qx can be contained in an interval if it’s also contained in all its predecessors in the sorted list • We can simply walk along sorted lists reporting intervals & stop when we encounter I s.t. qx I M. C. Lin

  5. Interval Trees • If I = 0, then the interval tree is a leaf • Otherwise, let xmid be the median of the endpoints of the intervals, let Ileft:= { [xj:xj’]  I : xj’ < xmid }, Imid:= { [xj:xj’]  I : xj xmid  xj’ }, Iright:= { [xj:xj’]  I : xmid < xj }. The interval trees consists of a root node v storing xmid. • The set Imid is stored twice: once in a list Lleft(v) that is stored on the left endpoints of the intervals, once in a list Lright(v) that is stored on the right endpoints of intervals • The left subtree of v is an interval tree for Ileft • The right subtree of v is an interval tree for Iright M. C. Lin

  6. ConstructIntervalTree(I) Input: A set I of intervals on the real line. Output: The root of an interval tree for I . 1. ifI = 0 2. then return an empty leave 3. else Create a node v. Compute xmid, the medianof the set of interval endpoints, and store xmid with v. 4.Compute Imidand construct two sorted lists for Imid: a list Lleft(v) sorted on left endpoint & a list Lright (v) sorted on right endpoint. Store these two lists at v. 5. lc(v) ConstructIntervalTree(Ileft) 6.rc(v) ConstructIntervalTree(Iright) 7. return v M. C. Lin

  7. QueryIntervalTree(v, qx) Input: The root v of an interval tree and a query point qx Output: All intervals that contain qx 1. ifvis not a leaf 2. then if qx < xmid(v) 3. then Walk along the list Lleft(v), starting at the interval with the leftmost endpoint, reporting all the intervals that contain qx. Stop as soon as an interval does not contain qx. 4. QueryIntervalTree(lc(v), qx) 5. else Walk along the list Lright(v), starting at the interval with the rightmost endpoint, reporting all the intervals that contain qx. Stop as soon as an interval does not contain qx. 6. QueryIntervalTree(rc(v), qx) M. C. Lin

  8. Algorithm Analysis • An interval tree for a set I of n intervals uses O(n) storage, has depth O(logn) and can be built in O(n log n) time. Using the interval tree we can report all intervals containing a query point in O(k + log n) time, where k is no. of reported intervals. • Let S be a set of n horizontal segments in the plane. The segments intersecting a vertical query segment can be reported in O(log2n + k) time with a data structure of O(n log n) storage, where k is the number of reported segments. The structure can be built in O(n log n) time. • Let S be a set of n axis-parallel segments in the plane. The segments intersecting an axis-parallel rectangular query window can be reported in O(log2n + k) time with a data structure of O(n log n) storage, where k is number of reported segments. The structure can be built in O(n log n) time. M. C. Lin

  9. Motivation for Priority Search Trees • Replacing RangeTrees: A 2d rectangle query on P asks for points in P lying inside a query window (-:qx]x[qy:qy’].Use ideas from 1d range query. • Use a heap to answer 1d query if px (-:qx]and partition using the y-coordinates. • Root of the tree stores the point with minimum x-value and the remainder is partitioned into 2 equal sets. • The 2 sets are partitioned into sets above & below • Construct the tree recursively M. C. Lin

  10. Priority Search Trees • If P = 0, then the priority search tree is an empty leaf • Otherwise, let pmin be the point in P with the smallest x-coordinate and ymid be the y-median of the rest in P. Let Pbelow:= { p  P\{pmin}: py< ymid }, Pabove:= { p P\{pmin}: py > ymid }. • The priority search trees consists of a root node v where the point p(v) := pmin and the value y(v) := ymin are stored. • The left subtree of v is a priority search tree for Pbelow • The right subtree of v is a priority search tree for Pabove M. C. Lin

  11. ReportInSubTree(v, qx) Input:The root v of a subtree of a priority search tree and a value qx Output: All points in the subtree with x-coordinate at most qx 1. ifvis not a leaf and (p(v))x  qx 2. then Report p(v) 3. ReportInSubTree(lc(v), qx) 4. ReportInSubTree(rc(v), qx) M. C. Lin

  12. QueryPrioSearchTree(T,(-:qx]x[qy:qy’]) Input: A priority search tree and a range unbounded to the left Output: All points lying in the range 1. Search with qy and qy’ in T. Let vsplit be node where 2 search paths split 2. for each node v on the search path of qy or qy’ 3. do if p(v) (-:qx]x[qy:qy’] then report p(v) 4. for each node v on the search path of qyin the left subtree of vsplit 5. do if the search path goes left at v 6. then ReportInSubtree(rc(v), qx) 7. for each node v on the search path of qy’ in the right subtree of vsplit 8. do if the search path goes right at v 9. then ReportInSubtree(lc(v), qx) M. C. Lin

  13. Algorithm Analysis • A priority search tree for a set P of n points in the plane uses O(n) storage & can be built in O(n log n) time. Using the priority search tree we can report all points in a query range of the form (-:qx]x[qy:qy’] in O(k + log n) time, where k is the number of reported points. M. C. Lin

  14. Segment Tree Data Structures • The skeleton of the segment tree is a balanced binary tree T. The leaves of T correspond to the elementary intervals induced by the endpoints of the intervals in I in an ordered way: the leftmost leaf corresponds to the leftmost elementary interval, and so on. The elementary interval corresponding to leaf u is denoted Int(u). • The internal nodes of correspond to intervals that are the union of elementary intervals: the interval Int(v) corresponding to node v is the union of the elementary intervals Int(u) of the leaves in the subtree rooted at v. (implying Int(v) is the union of its two children) • Each node or leaf v in T stores the interval Int(v) and a set I(v)I of intervals (e.g. in a linked list). This canonical subset of node v contains the intervals [x:x’]I s.t. Int(v)[x:x’] & Int(parent(v))[x:x’] (See the diagrams in class) M. C. Lin

  15. QuerySegmentTree(v, qx) Input:The root v of a (subtree of a) segment tree and a query point qx Output: All intervals in the tree containing qx 1. Report all the intervals in I(v) 2. ifvis not a leaf 3. then if qx  Int(lc(v)) 4. then QuerySegmentTree(lc(v), qx) 5. else QuerySegmentTree(rc(v), qx) M. C. Lin

  16. Constructing Segment Trees • Sort the endpoints on the intervals in I in O(n log n) time. This gives elementary intervals. • Construct a balanced binary tree on the elementary intervals & determine for each node v of the tree the interval Int(v) it represents. • Compute the canonical subsets by inserting one interval at a time into T. (See the next procedure) M. C. Lin

  17. InsertSegmentTree(v, [x:x’]) Input: The root of a (subtree of a) segment tree and an interval Output: The interval will be stored in the subtree 1. if Int(v)  [x:x’] 2. then store [x:x’] at v 3. else if Int(lc(v)) [x:x’]  0 4. then InsertSegmentTree(lc(v), qx) 5. if Int(rc(v)) [x:x’]  0 6. then InsertSegmentTree(rc(v), qx) M. C. Lin

  18. Algorithm Analysis • A segment tree for a set I of n intervals uses O(n log n) storage and can be built in O(n log n). Using the segment tree we can report all intervals that contain a query point in O(log n + k) time, where k is the number of reported intervals. • Let S be a setof n segments in the plane with disjoint interiors. The segments intersecting an axis-parallel rectangular query window can be reported in O(log2n+k) time with a data structure that uses O(n log n) storage, where k is the number of reported segments. The structure can be built in O(n log n) time. M. C. Lin

More Related