Geometric Data Structures

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Two Segments Intersect?
Polygon Triangulation
Computational Geometry
INTERVAL TREE & SEGMENTATION TREE
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
COSC 6114 Prof. Andy Mirzaian. References: [M. de Berge et al] chapter 5 Applications: Data Base GIS, Graphics: crop-&-zoom, windowing.
Brute-Force Triangulation
2/3/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Triangulations and Guarding Art Galleries II Carola Wenk.
UNC Chapel Hill M. C. Lin Polygon Triangulation Chapter 3 of the Textbook Driving Applications –Guarding an Art Gallery –3D Morphing.
Zoo-Keeper’s Problem An O(nlogn) algorithm for the zoo-keeper’s problem Sergei Bespamyatnikh Computational Geometry 24 (2003), pp th CGC Workshop.
Orthogonal Range Searching 3Computational Geometry Prof. Dr. Th. Ottmann 1 Orthogonal Range Searching 1.Linear Range Search : 1-dim Range Trees 2.2-dimensional.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
Computational Geometry, WS 2007/08 Lecture 15 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften.
Lecture 5: Orthogonal Range Searching Computational Geometry Prof. Dr. Th. Ottmann 1 Orthogonal Range Searching 1.Linear Range Search : 1-dim Range Trees.
Special Cases of the Hidden Line Elimination Problem Computational Geometry, WS 2007/08 Lecture 16 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen,
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 – Part III Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
1 Geometric Solutions for the IP-Lookup and Packet Classification Problem (Lecture 12: The IP-LookUp & Packet Classification Problem, Part II) Advanced.
Geometric Data Structures Computational Geometry, WS 2007/08 Lecture 13 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
Voronoi Diagrams.
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
O RTHOGONAL R ANGE S EARCHING الهه اسلامی فروردین 92, 1.
Fractional Cascading and Its Applications G. S. Lueker. A data structure for orthogonal range queries. In Proc. 19 th annu. IEEE Sympos. Found. Comput.
AALG, lecture 11, © Simonas Šaltenis, Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.
Orthogonal Range Searching I Range Trees. Range Searching S = set of geometric objects Q = query object Report/Count objects in S that intersect Q Query.
Randomized Algorithms - Treaps
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
UNC Chapel Hill M. C. Lin Point Location Reading: Chapter 6 of the Textbook Driving Applications –Knowing Where You Are in GIS Related Applications –Triangulation.
UNC Chapel Hill M. C. Lin Orthogonal Range Searching Reading: Chapter 5 of the Textbook Driving Applications –Querying a Database Related Application –Crystal.
UNC Chapel Hill M. C. Lin Linear Programming Reading: Chapter 4 of the Textbook Driving Applications –Casting/Metal Molding –Collision Detection Randomized.
UNC Chapel Hill M. C. Lin Line Segment Intersection Chapter 2 of the Textbook Driving Applications –Map overlap problems –3D Polyhedral Morphing.
External Memory Algorithms for Geometric Problems Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)
14/13/15 CMPS 3130/6130 Computational Geometry Spring 2015 Windowing Carola Wenk CMPS 3130/6130 Computational Geometry.
B-trees and kd-trees Piotr Indyk (slides partially by Lars Arge from Duke U)
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
Lars Arge Presented by Or Ozery. I/O Model Previously defined: N = # of elements in input M = # of elements that fit into memory B = # of elements per.
2IL50 Data Structures Fall 2015 Lecture 9: Range Searching.
Orthogonal Range Search
Segment Trees - motivation.  When one wants to inspect a small portion of a large and complex objects. Example: –GIS: windowing query in a map.
Computational Geometry Piyush Kumar (Lecture 5: Range Searching) Welcome to CIS5930.
UNC Chapel Hill M. C. Lin Computing Voronoi Diagram For each site p i, compute the common inter- section of the half-planes h(p i, p j ) for i  j, using.
Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point.
UNC Chapel Hill M. C. Lin Delaunay Triangulations Reading: Chapter 9 of the Textbook Driving Applications –Height Interpolation –Constrained Triangulation.
CMPS 3130/6130 Computational Geometry Spring 2015
Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms.
February 17, 2005Lecture 6: Point Location Point Location (most slides by Sergi Elizalde and David Pritchard)
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
May 2012Range Search Algorithms1 Shmuel Wimer Bar Ilan Univ. Eng. Faculty Technion, EE Faculty.
CMPS 3130/6130 Computational Geometry Spring 2017
CSE 554 Lecture 5: Contouring (faster)
CMPS 3130/6130 Computational Geometry Spring 2017
Lecture 22 Binary Search Trees Chapter 10 of textbook
Segment tree and Interval Tree
Orthogonal Range Searching and Kd-Trees
Computational Geometry Capter:1-2.1
Segment Trees Basic data structure in computational geometry.
Reporting (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of the from: Given an interval I=[x1,x2]
Orthogonal Range Searching Querying a Database
I. The Problem of Molding
Shmuel Wimer Bar Ilan Univ., School of Engineering
CMPS 3130/6130 Computational Geometry Spring 2017
Range Queries on Uncertain Data
CMPS 3130/6130 Computational Geometry Spring 2017
Presentation transcript:

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

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. UNC Chapel Hill M. C. Lin

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. UNC Chapel Hill M. C. Lin

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 containing xmid Ileft: those complete lie to the left & cannot intersect l Iright: those complete lie to the right & cannot intersect l 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 UNC Chapel Hill M. C. Lin

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 UNC Chapel Hill M. C. Lin

ConstructIntervalTree(I) Input: A set I of intervals on the real line. Output: The root of an interval tree for I . 1. if I = 0 2. then return an empty leave 3. else Create a node v. Compute xmid, the median of the set of interval endpoints, and store xmid with v. 4. Compute Imid and 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 UNC Chapel Hill M. C. Lin

QueryIntervalTree(v, qx) Input: The root v of an interval tree and a query point qx Output: All intervals that contain qx 1. if v is 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 6. QueryIntervalTree(rc(v), qx) UNC Chapel Hill M. C. Lin

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. UNC Chapel Hill M. C. Lin

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 UNC Chapel Hill M. C. Lin

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 UNC Chapel Hill M. C. Lin

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. if v is not a leaf and (p(v))x  qx 2. then Report p(v) 3. ReportInSubTree(lc(v), qx) 4. ReportInSubTree(rc(v), qx) UNC Chapel Hill M. C. Lin

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 qy in 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) UNC Chapel Hill M. C. Lin

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. UNC Chapel Hill M. C. Lin

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) UNC Chapel Hill M. C. Lin

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. if v is not a leaf 3. then if qx  Int(lc(v)) 4. then QuerySegmentTree(lc(v), qx) 5. else QuerySegmentTree(rc(v), qx) UNC Chapel Hill M. C. Lin

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) UNC Chapel Hill M. C. Lin

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) UNC Chapel Hill M. C. Lin

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 set of 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. UNC Chapel Hill M. C. Lin