AALG, lecture 11, © Simonas Šaltenis, 2004 1 Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Nearest Neighbor Search
INTERVAL TREE & SEGMENTATION TREE
COL 106 Shweta Agrawal and Amit Kumar
Lecture 3: Parallel Algorithm Design
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.
COSC 6114 Prof. Andy Mirzaian. References: [M. de Berge et al] chapter 5 Applications: Data Base GIS, Graphics: crop-&-zoom, windowing.
Searching on Multi-Dimensional Data
Advanced Algorithm Design and Analysis (Lecture 10) SW5 fall 2004 Simonas Šaltenis E1-215b
AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 – Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
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.
Orthogonal Range Searching-1Computational Geometry Prof. Dr. Th. Ottmann 1 Orthogonal Range Searching 1.Linear Range Search : 1-dim Range Trees 2.2-dimensional.
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.
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 – Part III Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
Persistent Data Structures Computational Geometry, WS 2007/08 Lecture 12 Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
I/O-Algorithms Lars Arge Aarhus University March 5, 2008.
I/O-Algorithms Lars Arge Aarhus University March 9, 2006.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 - Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part II Prof. Dr. Th. Ottmann Summer Semester 2006.
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
David Luebke 1 7/2/2015 Medians and Order Statistics Structures for Dynamic Sets.
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.
 This lecture introduces multi-dimensional queries in databases, as well as addresses how we can query and represent multi- dimensional data.
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.
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
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.
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)
Bin Yao Spring 2014 (Slides were made available by Feifei Li) Advanced Topics in Data Management.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
Multi-dimensional Search Trees
2IL50 Data Structures Fall 2015 Lecture 9: Range Searching.
Orthogonal Range Search
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
Lecture 2: External Memory Indexing Structures CS6931 Database Seminar.
Computational Geometry Piyush Kumar (Lecture 5: Range Searching) Welcome to CIS5930.
Search Trees: BSTs and B-Trees David Kauchak cs161 Summer 2009.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Multi-dimensional Search Trees CS302 Data Structures Modified from Dr George Bebis.
Binary Search Trees (BST)
Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point.
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
CMPS 3130/6130 Computational Geometry Spring 2015
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.
Geometric Data Structures
CMPS 3130/6130 Computational Geometry Spring 2017
KD Tree A binary search tree where every node is a
Segment tree and Interval Tree
Orthogonal Range Searching and Kd-Trees
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
Shmuel Wimer Bar Ilan Univ., School of Engineering
CMPS 3130/6130 Computational Geometry Spring 2017
CSC 143 Binary Search Trees.
CMPS 3130/6130 Computational Geometry Spring 2017
Presentation transcript:

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 the range trees; to see how data structures can be used to trade the space used for the running time of queries

AALG, lecture 11, © Simonas Šaltenis, Range queries How do you efficiently find points that are inside of a rectangle? Orthogonal range query ([x 1, x 2 ], [y 1,y 2 ]): find all points (x, y) such that x 1 <x<x 2 and y 1 <y<y 2 Useful also as a multi-attribute database query x y x1x1 x2x2 y1y1 y2y2

AALG, lecture 11, © Simonas Šaltenis, Preprocessing How much time such a query would take? Rules of the game: We preprocess the data into a data structure Then, we perform queries and updates on the data structure Analysis: Preprocessing time Efficiency of queries (and updates) The size of the structure Assumption: no two points have the same x- coordinate (the same is true for y-coordinate).

AALG, lecture 11, © Simonas Šaltenis, D range query How do we do a 1D range query [x 1, x 2 ]? Balanced BST where all data points are stored in the leaves The size of it? Where do we find the answer to a query? T … b 1 q 1 a 1 … b 2 q 2 a 2 … Search path for x 2 Search path for x 1 Total order of data points

AALG, lecture 11, © Simonas Šaltenis, D range query How do we find all these leaf nodes? A possibility: have a linked list of leaves and traverse from q 1 to q 2 but, will not work for more dimensions… Sketch of the algorithm: Find the split node Continue searching for x1, report all right-subtrees Continue searching for x2, report all left-subtrees When leaves q 1 and q 2 are reached, check if they belong to the range Why is this correct?

AALG, lecture 11, © Simonas Šaltenis, Analysis of 1D range query What is the worst-case running time of a query? It is output-sensitive: two traversals down the tree plus the O(k), where k is the number of reported data points: O(log n + k) What is the time of construction? Sort, construct by dividing into two, creating the root and conquering the two parts recursively O(n log n) Size: O(n)

AALG, lecture 11, © Simonas Šaltenis, D range query How can we solve a 2D range query? Observation – 2D range query is a conjunction of two 1D range queries: x 1 <x<x 2 and y 1 <y<y 2 Naïve idea: have two BSTs (on x-coordinate and on y-coordinate) Ask two 1D range queries Return the intersection of their results What is the worst-case running time (and when does it happen)? Is it output-sensitive? x y x1x1 x2x2 y1y1 y2y2

AALG, lecture 11, © Simonas Šaltenis, Range tree Idea: when performing search on x-coordinate, we need to start filtering points on y-coordinate earlier! Canonical subset P(v) of a node v in a BST is a set of points (leaves) stored in a subtree rooted at v Range tree is a multi-level data structure: The main tree is a BST T on the x-coordinate of points Any node v of T stores a pointer to a BST T a (v) (associated structure of v), which stores canonical subset P(v) organized on the y-coordinate 2D points are stored in all leaves! BST on y-coords P(v)P(v) Ta(v)Ta(v) T P(v)P(v) v BST on x-coords

AALG, lecture 11, © Simonas Šaltenis, Querying the range tree How do we query such a tree? Use the 1DRangeSearch on T, but replace ReportSubtree(w) with 1DRangeSearch(T a (w), y 1, y 2 ) What is the worst-case running time? Worst-case: We query the associated structures on all nodes on the path down the tree On level j, the depth of the associated structure is Total running time: O(log 2 n + k)

AALG, lecture 11, © Simonas Šaltenis, Size of the range tree What is the size of the range tree? At each level of the main tree associated structures store all the data points once (with constant overhead) (Why?) : O(n) There are O(log n) levels Thus, the total size is O(n log n)

AALG, lecture 11, © Simonas Šaltenis, Building the range tree How do we efficiently build the range tree? Sort the points on x and on y (two arrays: X,Y) Take the median v of X and create a root, build its associated structure using Y Split X into sorted X L and X R, split Y into sorted Y L and Y R (s.t. for any pX L or pY L, p.x < v.x and for any pX R or pY R, p.x  v.x) Build recursively the left child from X L and Y L and the right child from X R and Y R What is the running time of this? O(n log n)

AALG, lecture 11, © Simonas Šaltenis, Range trees: summary Range trees Building (preprocessing time): O(n log n) Size: O(n log n) Range queries: O(log 2 n + k) Running time can be improved to O(log n + k) without sacrificing the preprocessing time or size Layered range trees (uses fractional cascading) Priority range trees (uses priority search trees as associated structures)

AALG, lecture 11, © Simonas Šaltenis, Kd-trees What if we want linear space? Idea: partition trees – generalization of binary search trees Kd-tree: a binary tree Data points are at leaves For each internal node v: x-coords of left subtree  v x-coords of right subtree, if depth of v is even (split with vertical line) y-coords of left subtree  v  y-coords of right subtree, if depth of v is odd (split with horizontal line) Space: O(n) – points are stored once.

AALG, lecture 11, © Simonas Šaltenis, Example kd-tree d e b a d e b a c c f g f g x y x

AALG, lecture 11, © Simonas Šaltenis, Draw a kd-tree Draw a kd-tree storing the following data points a b c d e f g h

AALG, lecture 11, © Simonas Šaltenis, Querying the kd-tree How do we answer a range query? Observation: Each internal node v corresponds to a region(v) (where all its children are included). We can maintain region(v) as we traverse down the tree d e b a d e b a c c f g f g

AALG, lecture 11, © Simonas Šaltenis, Querying the kd-tree The range query algorithm (query range R): If region(v) does not intersect R, do not go deeper into the subtree rooted at v If region(v) is fully contained in R, report all points in the subtree rooted at v If region(v) only intersects with R, go recursively into v’s children.

AALG, lecture 11, © Simonas Šaltenis, Analysis of the search alg. What is the worst-case running time of the search? Traversal of subtrees v, such that region(v) is fully contained in R adds up to O(k). We need to find the number of regions that intersect R – the regions which are crossed by some border of R As an upper bound for that, let’s find how many regions a crossed by a vertical (or horizontal) line What recurrence can we write for it? Solution: Total time:

AALG, lecture 11, © Simonas Šaltenis, Building the kd-tree How do we build the kd-tree? Sort the points on x and on y (two arrays: X,Y) Take the median v of X (if depth is even) or Y (if depth is odd) and create a root Split X into sorted X L and X R, split Y into sorted Y L and Y R, s.t. for any pX L or pY L, p.x < v.x (if depth is even) or p.y < v.y (if depth is odd) for any pX R or pY R, p.x  v.x (if depth is even) or p.y  v.y (if depth is odd) Build recursively the left child from X L and Y L and the right child from X R and Y R What is the running time of this? O(n log n)

AALG, lecture 11, © Simonas Šaltenis, Kd-trees: summary Kd-tree: Building (preprocessing time): O(n log n) Size: O(n) Range queries: