Quadtrees Hierarchical grids

Slides:



Advertisements
Similar presentations
WSPD Applications.
Advertisements

INTERVAL TREE & SEGMENTATION TREE
Cutting trees and the cutting lemma Presented by Amir Mograbi.
Efficient access to TIN Regular square grid TIN Efficient access to TIN Let q := (x, y) be a point. We want to estimate an elevation at a point q: 1. should.
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.
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
Dynamic Planar Convex Hull Operations in Near- Logarithmic Amortized Time TIMOTHY M. CHAN.
2/14/13CMPS 3120 Computational Geometry1 CMPS 3120: Computational Geometry Spring 2013 Planar Subdivisions and Point Location Carola Wenk Based on: Computational.
Greedy Algorithms Greed is good. (Some of the time)
Searching on Multi-Dimensional Data
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
Lectures on Recursive Algorithms1 COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski.
Quadtrees Raster and vector.
2-dimensional indexing structure
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
6/14/2015 6:48 AM(2,4) Trees /14/2015 6:48 AM(2,4) Trees2 Outline and Reading Multi-way search tree (§3.3.1) Definition Search (2,4)
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Point Location Computational Geometry, WS 2007/08 Lecture 5 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
B + -Trees (Part 1) COMP171. Slide 2 Main and secondary memories  Secondary storage device is much, much slower than the main RAM  Pages and blocks.
1 Separator Theorems for Planar Graphs Presented by Shira Zucker.
R-Trees 2-dimensional indexing structure. R-trees 2-dimensional version of the B-tree: B-tree of maximum degree 8; degree between 3 and 8 Internal nodes.
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
Tirgul 6 B-Trees – Another kind of balanced trees.
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.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
UNC Chapel Hill M. C. Lin Orthogonal Range Searching Reading: Chapter 5 of the Textbook Driving Applications –Querying a Database Related Application –Crystal.
CSCE350 Algorithms and Data Structure Lecture 17 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
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)
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
2IL50 Data Structures Fall 2015 Lecture 9: Range Searching.
Lecture 2: External Memory Indexing Structures CS6931 Database Seminar.
3.1. Binary Search Trees   . Ordered Dictionaries Keys are assumed to come from a total order. Old operations: insert, delete, find, …
Spatial Indexing Techniques Introduction to Spatial Computing CSE 5ISC Some slides adapted from Spatial Databases: A Tour by Shashi Shekhar Prentice Hall.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
Spatial Data Management
CSE 554 Lecture 5: Contouring (faster)
COMP261 Lecture 23 B Trees.
Computational Geometry
Geometric Data Structures
Multiway Search Trees Data may not fit into main memory
Chapter 5 : Trees.
COSC160: Data Structures Binary Trees
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Summary of General Binary search tree
B+ Tree.
KD Tree A binary search tree where every node is a
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
Advanced Topics in Data Management
Orthogonal Range Searching and Kd-Trees
Fast Trie Data Structures
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Enumerating Distances Using Spanners of Bounded Degree
Multi-Way Search Trees
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
Ch. 8 Priority Queues And Heaps
cse 521: design and analysis of algorithms
(2,4) Trees (2,4) Trees (2,4) Trees.
Introduction Wireless Ad-Hoc Network
A Robust Data Structure
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
Kinetic Collision Detection for Convex Fat Objects
(2,4) Trees /6/ :26 AM (2,4) Trees (2,4) Trees
Binary Search Trees < > = Dictionaries
Minimum Spanning Trees
Presentation transcript:

Quadtrees Hierarchical grids Seminar on Geometric Approximation Algorithms Speaker : Hadar Boker

Lecture Outline Motivation Quadtrees construction Fast point location in a quadtree Compressed quadtree : definition Efficient construction of compressed quadtrees Fast point location in a compressed quadtree Dynamic quadtree : Ordering of nodes and points Performing operations on a quadtree using Q-order

Preliminaries For a grid G, we call  the width or side-length. G partitions the plane into square regions, which we call grid cells. Every grid cell □ of G has a unique ID; let p=(x,y) be any point in □, and consider the pair of integer numbers id□=id(p)=(└x/┘,└y/┘). For a point set P and a parameter , the partition of P into subsets by the grid G is denoted by G(P). Two points p,qP belong to the same set in the partition G(P), if both points belong to the same grid cell; that is, id(p)=id(q).

Motivation Let Pmap be a partition of the unit square into polygons. Preprocess Pmap for point-location queries. So that given a query point we need figure out which polygon contains the query. How can we solve this problem? One possibility : quadtrees !

Quadtrees Construction □v Build a tree T, where: Every node v corresponds to a cell □v (and the root?) Each node has four children The conflict list of the square □v is a list of all the polygon of Pmap that intersect □v. Let  be a constant (which denote at least the number of polygons of Pmap meeting in one common corner) The construction is recursive.

Back to our problem… Given a query point q, in the unit square: How can we compute the polygon of Pmap containing q? We assume that the polygons are simple (e.g. triangles), and thus, the quadtree would have linear complexity in the input size. Can we perform a better point-location query?

Fast point-location: Definitions A square is a canonical square if: It is contained inside the unit square It is a cell in a grid Gr r is a negative power of 2  It might correspond to a node in a quadtree We will refer to such a grid Gr as a canonical grid. Consider a node v of depth i, its associated square □v. Then the side-length of □v is 2-i, and it is a canonical square in the canonical grid G2-i. We will refer to l (v) = -i as the level of v.

Fast point-location: Definitions Unit square □r root □w 1/8 □u v □v 1/4 u 1/2 w Level (-i) Canonical grid (G2-i) Side length (2-i) Depth (i) Node G1 20=1 root -1 G1/2 2-1=1/2 1 v -2 G1/4 2-2=1/4 2 u -3 G1/8 2-3=1/8 3 w

Fast point-location: Definitions A node v of a quadtree is uniquely defined by the triple id(v)=(l (v), └x/r┘,└y/r┘( where (x,y) is any point in □v , and r=2l(v). Corollary: Given a query point q and a desired level l we can compute the ID of the quadtree cell of this level that contains q in constant time. How can this help us?

Fast point-location: Algorithm binary search for the leaf QTGetNode(T,q,d): returns (in constant time) the node v of depth d in the quadtree T such that □v contains the point q.

Fast point-location: Example □r r □u □z u z q QTFastPLI(T,q,l=0,h=3) m = └(0+3)/2┘=1 v := QTGetNode(T,q,1) := u (≠null) w := child(v,q) = z (≠null) QTFastPLI(T,q, l=1+1, h=3) m =└(2+3)/2┘=2 v := QTGetNode(T,q,2) := z (≠null) w := child(v,q) = null return w ( = z )

Fast point-location: Algorithm Lemma: given a quadtree T of size n and of height h, one can preprocess it (using hashing) in linear time, such that one can perform a point-location query in O(log h) time. However, the height, h, may be unbounded.

Compressed quadtrees

Spread Definition: For a set P of n points in a metric space, let max p,qP ||p-q|| min p,q P, pq ||p-q|| be the spread of p. Intuitively, the spread tells us the range of distances that P possesses. Φ(P) =

Spread Lemma: Let P be a set of n points contained in the unit square, such that diam(P) = max p,qP ||p-q|| ≥ ½. Let T be a quadtree of P constructed over the unit square, where no leaf contains more than one point of P. then, the depth of T is bounded by O(log Φ), it can be constructed in O(n log Φ) time, and the total size of T is O(n log Φ), where Φ=Φ(P).

Spread Proof: Build recursively a quadtree T for P (how?) Diam 2l(v) Now, let us bound the depth of T: Consider p,qP , a node v with l (v)=└log ||p-q||┘- 1 diam(□v) 2l(v) □v Thus, □v can not contain both p and q. In particular, any node u of T of level r = -┌log Φ┐-2 can contain at most one point of p (i.e. u is a leaf). Thus, all the nodes of T are of depth O(log Φ).

How can quadtrees be compressed? The quadtree generated by the Lemma has a lot of nodes which are of degree one. A node v has more than one child, only if it has at least two children x and y such that both □x and □y contain points of p. How can we get more compact data structure? For example: v y x

How can quadtrees be compressed? Store inside each node v, its □v and its level l (v). A path of vertices, all of degree one, will be replaced by the first vertex in this path. Its only child would be the last vertex in this path. This compressed node v has a single child, region rgv that v “controls” seen as the gray area below. If v is uncompressed node the region that v is in charge of is a square rgv = □v The resulting tree is a compressed quadtree A compressed quadtree has linear size

Compressed quadtrees: Example This compressed quadtree has depth and size θ(n). It looks like a linked list.

Bit twiddling & compressed quadtrees Definition: Let α,β[0,1) be two real numbers. Assume these numbers in base two are written as α=0.α1α2… and β=0.β1β2… Let bit∆(α,β) be the index of the first bit after the period in which they differ. For example: bit∆(7/8=0.1112, 3/4=0.1102) = 3 Lemma: if one can compute a compressed quadtree of two points in constant time, then one can compute bit∆(α,β) in constant time.

Bit twiddling & compressed quadtrees Proof: Given α and β we need to compute bit∆(α,β) If |α-β|>1/128: compute bit∆(α,β) in constant time. Otherwise, build a compressed trie for a set {α,β}: The root is a compressed node. Its only child has side-length 2-i (l(v) = -i) α and β are identical in the first i bits. They differ at the (i+1)th bit, as the next level of the quadtree splits them into different subtrees. r

Efficient construction of compressed quadtrees Theorem: Given a set P of n points in the plane, one can compute a compressed quadtree of P in O(n log n) deterministic time. In our proof we will use two lemmas: Lemma 1: Given a set P of n points in Rd, and parameter k, one can compute in O(n(n/k)d) deterministic time, a ball b that contains k points of P and its radius radius(b) ≤2ropt(P,k), where ropt(P,k) is the radius of the smallest ball in Rd containing k points of P. Lemma 2: For any point set P and α>0, we have that if α≤2ropt(P,k) then any cell of grid Gα contains at most 5k points.

Efficient construction of compressed quadtrees Proof (of Theorem): Compute, in linear time, a disk D of radius r, which contains at least n/10 of the points of P, such that r≤2ropt(P,n/10). (According to lemma 1, it’s possible) Consider the grid Gα where α=2└log r┘. It has a cell that contains at least (n/10)/25 points of P (since D covered by 25 grid cell of Gα and α≥r/2) No grid cell contains more than 5(n/10) points, by lemma 2. r α

Efficient construction of compressed quadtrees Proof (cont.): Compute Gα(P) and find the cell □ containing the largest number of points. Let Pin be the set of points inside this cell □ and Pout be the set of points outside this cell □. we know that |Pin| ≥ n/250 and |Pout| ≥ n/2 Compute (recursively) the compressed quadtrees for Pin (i.e. Tin) and Pout (i.e. Tout).

Efficient construction of compressed quadtrees Proof (cont.): Create a node in both quadtrees that corresponds to □ For Tin this would just be the root node vin (Pin⊆ □) For Tout this would be new leaf node vout (Pout ∩ □ = ∅) Hang vout on vin creating a compressed quadtree for P. The overall construction time is: T(n) = O(n) + T(|Pin|) + T(|Pout|) = O(n log n) Where did the bit∆ operation get used?

Fingering a compressed quadtree: definitions Back to “Point Location query”… Traversing down the quadtree Binary search Finger tree Definition: Let T be a tree with n nodes. A separator in T is a node v, such that if we remove v from T, we remain with a forest, such that every tree in the forest has at most ┌n/2┐ vertices.

Fingering a compressed quadtree: definitions Lemma: Every tree has a separator, and it can be computed in linear time. Proof: consider T to be a rooted tree with n nodes. Precompute for every node the number of nodes in its subtree (bottom-up) Set v to be lowest node in T such that its subtree has ≥ ┌n/2┐nodes in it (how?) How to build our finger tree?

Fingering a compressed quadtree: fast point location Finger tree 1 3 3 2 1 4 5 4 5 2 7 6 7 6 We get a balanced tree which has cross pointers (fingers) into the original tree

Fingering a compressed quadtree: fast point location 2 1 Given a query point q… Traverse T’ (finger tree), while at node fvT’: If q □v, continue into the child of fv which corresponds to the connected component outside □v Otherwise continue into the child that contains q. We have to check O(1) children, constant time per node D(n) ≤ 1+ D(┌n/2┐) = O(log n) , while D:= depth(T’) Thus, Point location query in T’ takes logarithmic time. Now, let us bound the preprocessing time 3 4 5 6 7

Fingering a compressed quadtree: fast point location Theorem: Given a compressed quadtree T of size n, one can preprocess it, in time O(n log n), such that given a query point, one can return the lowest node in T whose region contains q in O(log n) time. Proof: T(n) = O(n) + where n1,…,nt are the sizes of the subtrees formed by removing the separator node from T. We know that t=O(1) and ni ≤ ┌n/2┐, for all i. As such, T(n) = O(n log n).

Dynamic quadtrees

Dynamic quadtrees: introduction The idea is: define an order on the compressed quadtree nodes. store the compressed quadtree nodes in a data structure for ordered sets. How to perform basic operations: In regular quadtree: Point location Overlaying In compressed quadtrees: Insertion & Deletion

Ordering of nodes and points Consider a regular quadtree T, and DFS traversal on T. Consider any two canonical squares □ and ■ in T. If □ gets visited before ■, we denote this fact by □ < ■ Consider a point p and a canonical square □Gi. If p□ then we will say that □ < p Otherwise, let ■ be the cell in Gi that contains p We have that □ < p if and only if □ < ■ Consider two points p and q which lie in different cells, in Gi: □p and □q. Then p<q if and only if □p < □q

Ordering of nodes and points We will refer to the ordering induced by < as the Q-order The ordering < when restricted only to points, is know as the Z-order

Computing the Q-order quickly Definition: for any two points p,q[0,1)2, let lca(p,q) denote the smallest canonical square that contains both p and q. ( The Ica of two cells is the Ica of their centers ) To compute lca(p,q) we use bit∆ operation Q-order can be resolved in constant time. q p

Computing the Q-order quickly determine Q-order of two cells □ and ■ : If □ ⊆ ■ then ■ < □ If ■ ⊆ □ then □ < ■ Otherwise, let ◙ = Ica(□,■). determine which children of ◙ contain □ and ■ resolve this query using DFS

Performing a point location in a (regular) quadtree using Q-order The quadtree leaf containing q is the last cell □ in the ordered list such that □ < q. Correctness: Let □q be the leaf of T whose cell contains q. By definition: □q < q The only bad scenario: □q < □ < q But this implies: □ must be contained inside □q Contradiction to our assumption that □q is a leaf. w z q u v

Performing overlaying two (regular) quadtrees using Q-order Given two quadtrees T’ and T’’ we would like to overlay them to compute their combined quadtree. (= minimal quadtree such that every cell of T’ and T’’ appears in it) Observation: if the two quadtrees are given as sorted list of their cells then their overlay is just the merged list, with replication removed.

Performing overlaying two (regular) quadtrees using Q-order z3 z4 w1 w2 u4 u3 w1 u3 w2 u4 z1 z2 v3 v4 u1 v1 v2 u2 u1 u2 r < u1 < u2 < v1 <…< v4 < u3 < w1< … < w4 < u4 r < u1 < u2 < u3 < w1 < w2 < z1…< z4 < w3 < w4 < u4 T2 : T1 : w3 w4 r z3 z4 u3 w1 w2 u4 z1 z2 v3 v4 v1 v2 u1 u2 r < u1 < u2 < v1 <…< v4 < u3 < w1 < w2 < z1 <…< z4 < w3 < w4 < u4

Performing operations on a (regular) quadtree using Q-order Conclusions Given a quadtree T, with its leaves stored in an ordered-set data-structure D according to the Q-order. Point-location query: O(Q(n)) time, where Q(n) is the time to perform search query in D. Compute merged quadtree: linear time.

Performing operations on a compressed quadtree using Q-order Note: A compressed node v, is stored according to the square □v but in fact it is in charge of the compressed region rgv  This will make things more complicated.

Point location in a compressed quadtree using Q-order If the query point q is contained inside a leaf of T: use simple binary search for predecessor of q. However, if q is contained inside the region of a compressed node, w, the predecessor to q might be some arbitrary leaf, v, that is contained inside w. (note: q is not stored in the quadtree) What to do in such a case?

Point location in a compressed quadtree using Q-order Example 2 Example 1 w w q q v v u z s u z s Q-order: w < z < s < v Predecessor Q-order(T,q) = □v q□v Ica(□v,q) = □u PredecessorQ-order(T, □u) = □w * node u was removed (compressing) Q-order: w < z < s < v Predecessor Q-order(T,q) = □v q□v Ica(□v,q) = □w PredecessorQ-order(T, □w) = □w * node u was removed (compressing)

Insertions in a compressed quadtree using Q-order q - a point to be inserted into the quadtree. w - the node such that qrgw There are 3 possibilities for insertions Case 1: The node w is a leaf and there is no point in it. store q at w.

Insertions in a compressed quadtree using Q-order Case 2: The node w is a leaf, and there is a point p already stored in w. p q p q r Ica(p,q) = □w r □w □w w t w t □t □t u (p) v (q) q r p q p r Ica(p,q)  □w w □w t □w □t w t z □t u (p) v (q)

Insertions in a compressed quadtree using Q-order Case 3: The node w is a compressed node. q w w w Ica(□z,q)  □w s u z Node of Ica (□z,q) = u t z t s z Node of q “store p”? t s

Deletions in a compressed quadtree using Q-order Deletion is done in a similar fashion: Delete the point from the node that contains it Trim away nodes that are no longer necessary q w w w Delete q u s t u w v t s (q)

Performing operations on a compressed quadtree using Q-order Conclusions Given a compressed quadtree T, with its leaves stored in an ordered-set data-structure D according to the Q-order. Point-location query: O(Q(n)) time, where Q(n) is the time to perform search query in D. Maintain a compressed quadtree: O(log n) time per operation (insertions, deletions and point location queries are supported).

Summary Quadtrees is one of the most powerful geometric data structure One important application: point-location query In a (regular) quadtree, point-location takes O(log h) time (using binary search) A compressed quadtree has linear size In compressed quadtree, point location takes O(log n) time (using finger tree) In dynamic quadtrees we store the nodes in a data structure for ordered sets (sorted by Q-order) We can perform operations on such quadtrees (point-location, insertion, deletion etc).

Thank you for listening!