Orthogonal range searching. The problem (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Interval Trees Store intervals of the form [li,ri], li <= ri.
Planar point location -- example
AVL-Trees (Part 2: Double Rotations) Lecture 19 COMP171 Fall 2006.
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.
Lecture 3: Parallel Algorithm Design
Chapter 4: Trees Part II - AVL Tree
Solution of Assignment 3 and Midterm CSC2100B. AVL Tree A binary search tree is a binary tree in which every node has larger key than the nodes in its.
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.
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
External Memory Geometric Data Structures
I/O-Algorithms Lars Arge University of Aarhus February 21, 2005.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
I/O-Algorithms Lars Arge Spring 2011 March 8, 2011.
Multiple-key indexes Index on one attribute provides pointer to an index on the other. If V is a value of the first attribute, then the index we reach.
Tirgul 5 AVL trees.
I/O-Algorithms Lars Arge Aarhus University February 13, 2007.
I/O-Algorithms Lars Arge Aarhus University February 16, 2006.
I/O-Algorithms Lars Arge University of Aarhus February 13, 2005.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
CSE 326: Data Structures AVL Trees
I/O-Algorithms Lars Arge Aarhus University March 5, 2008.
1 Lecture 20: Indexes Friday, February 25, Outline Representing data elements (12) Index structures (13.1, 13.2) B-trees (13.3)
Tirgul 5 Comparators AVL trees. Comparators You already know interface Comparable which is used to compare objects. By implementing the interface, one.
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
1 Database Tuning Rasmus Pagh and S. Srinivasa Rao IT University of Copenhagen Spring 2007 February 8, 2007 Tree Indexes Lecture based on [RG, Chapter.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
Balanced Search Trees CS 3110 Fall Some Search Structures Sorted Arrays –Advantages Search in O(log n) time (binary search) –Disadvantages Need.
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.
Splay Trees Splay trees are binary search trees (BSTs) that:
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.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
Storage CMSC 461 Michael Wilson. Database storage  At some point, database information must be stored in some format  It’d be impossible to store hundreds.
External Memory Algorithms for Geometric Problems Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)
Priority Queues and Binary Heaps Chapter Trees Some animals are more equal than others A queue is a FIFO data structure the first element.
Analysis of Red-Black Tree Because of the rules of the Red-Black tree, its height is at most 2log(N + 1). Meaning that it is a balanced tree Time Analysis:
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
Balanced Search Trees Fundamental Data Structures and Algorithms Margaret Reid-Miller 3 February 2005.
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.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location 
Index tuning-- B+tree. overview Overview of tree-structured index Indexed sequential access method (ISAM) B+tree.
Computational Geometry Piyush Kumar (Lecture 5: Range Searching) Welcome to CIS5930.
CSE373: Data Structures & Algorithms Lecture 7: AVL Trees Linda Shapiro Winter 2015.
CMPS 3130/6130 Computational Geometry Spring 2015
AVL TREES By Asami Enomoto CS 146 AVL Tree is… named after Adelson-Velskii and Landis the first dynamically balanced trees to be propose Binary search.
AVL Trees AVL (Adel`son-Vel`skii and Landis) tree = – A BST – With the property: For every node, the heights of the left and right subtrees differ at most.
Red-Black Trees an 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.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
3.1 Height-Balanced Trees 3.2 Weight-Balanced Trees
Red Black Trees Lecture 6.
G64ADS Advanced Data Structures
Lecture 3: Parallel Algorithm Design
B/B+ Trees 4.7.
CMPS 3130/6130 Computational Geometry Spring 2017
Balancing Binary Search Trees
Segment tree and Interval Tree
Orthogonal Range Searching and Kd-Trees
Chapter 14: Augmenting Data Structures
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]
Dynamic Data Structures for Simplicial Thickness Queries
AVL Search Tree put(9)
Dynamic rectangular intersection with priorities
AVL-Trees (Part 1).
CMPS 3130/6130 Computational Geometry Spring 2017
CSE 326: Data Structures Lecture #9 AVL II
Dynamic rectangular intersection with priorities
Presentation transcript:

Orthogonal range searching

The problem (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=[x 1,x 2 ] find all points in S that are in the interval

1-D solution Build a balanced tree using the points’ co-ordinates as the keys query: O(log n+k) space: O(n)

The problem (2-D) Given a set of points S on the plane, preprocess them to build structure that allows efficient queries of the from: Given an rectangle R=[x 1,x 2 ][y 1,y 2 ] find all points in S that are in the rectangle. P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7

Range Trees (2-D) P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 Maintain the points in a balanced search tree ordered by x-coor. In each internal node maintain the points in its subtree in a balanced search tree ordered by y

Range Trees (Contd.) P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7

P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7

Query processing Search by the first dimension gives us O(logn) trees which together contain the output. We search each of these trees to get the answer

Analysis (2-D) Space O(nlog n) Query O(log 2 n+k) Preprocessing O(nlog n)

Further facts Generalizes to d-dimensions Query time can be reduced using a technique called fractional cascading (we may talk about it later on)

The dynamic case Suppose the set S is not fixed We want to be able to insert and delete points, and make queries intermixed with insertions and deletions.

Easy in 1-D, just use a red-black tree or some other balance search tree

P4P4 P3P3 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7 Y

P4P4 P2P2 P1P1 P3P3 P2P2 P4P4 P1P1 P1P1 P2P2 P3P3 P4P4 P8P8 P7P7 P6P6 P5P5 P5P5 P8P8 P6P6 P7P7 Y P3P3 Y Y Y Y Y

May need to rebalance the primary tree by doing a rotation: y x B C x A y BC A  We have to rebuild the secondary data structures at x and y

Dynamic range trees (analysis) So we use BB(α) trees Then the amortized cost of rebalancing the primary tree is O(log n) and we get Query : O(log 2 n+k) Insert, delete : O(log 2 n) (amortized)

Priority search trees Suppose the query is unbouded from below, can we take advantage of this ? P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12

P1P1 A A P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 We put the lowest point at the root and the x-median (A) of the points other than the root P9P9 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 10 P 11 P 12

P1P1 A P4P4 B P7P7 P6P6 P8P8 P5P5 P2P2 P3P3 P 11 P 10 P9P9 How do we answer a query ? P 12 A P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 B

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 A P4P4 B P7P7 P6P6 P8P8 P5P5 P2P2 P3P3 P 11 P 10 P9P9 P 12

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 A P4P4 B P7P7 P6P6 P8P8 P5P5 P2P2 P3P3 P 11 P 10 P9P9 P 12 P4P4 P2P2 P6P6 You stop the search in the when you hit a point that is not in the answer

Priority search trees (analysis) query: O(log(n) + k) space: O(n) preprocessing: O(nlogn) How do we make them dynamic ?

Dynamic priority search trees P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 First put the points at the leaves of a red-black tree

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P2P2 P3P3 P7P7 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P4P4 P6P6 P6P6 P5P5 P 10 P 11 How does the insertion go ? Top-down: At each internal node put the smallest point in its subtree not already assigned to an internal node

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 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 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N We may also need to rebalance the tree… Is this a problem ?

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M M P

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 N M P P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N M M P P

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M P P Need a point to put here P This is incorrect P4P4 P5P5 M P5P5 P

Rotation, rotations… B CA BC A X X YZ Z is bubbled down into B or C Y is bubbled up from A or B

P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P1P1 P4P4 P2P2 P3P3 P7P7 P6P6 P6P6 P1P1 P2P2 P3P3 P4P4 P5P5 P8P8 P6P6 P7P7 P9P9 P 10 P 11 P 12 P5P5 P 10 P 11 N N N M M P P P4P4 P5P5 M P5P5 M P4P4