Range Reporting. Range Reporting. Range Reporting Problem. Applications

Similar documents
Range Reporting. Range reporting problem 1D range reporting Range trees 2D range reporting Range trees Predecessor in nested sets kd trees

Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b

Computational Geometry

Computational Geometry

January 10-12, NIT Surathkal Introduction to Graph and Geometric Algorithms

Computational Geometry

Orthogonal range searching. Range Trees. Orthogonal range searching. 1D range searching. CS Spring 2009

Lecture 3 February 9, 2010

Computational Geometry

CMSC 754 Computational Geometry 1

(2,4) Trees. 2/22/2006 (2,4) Trees 1

Range Searching and Windowing

Computational Geometry

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

Geometric data structures:

1 The range query problem

Predecessor. Predecessor. Predecessors. Predecessors. Predecessor Problem van Emde Boas Tries. Predecessor Problem van Emde Boas Tries.

Search Trees - 1 Venkatanatha Sarma Y

Orthogonal range searching. Orthogonal range search

Fast Evaluation of Union-Intersection Expressions

Binary Search Tree (3A) Young Won Lim 6/2/18

1D Range Searching (cont) 5.1: 1D Range Searching. Database queries

(2,4) Trees Goodrich, Tamassia. (2,4) Trees 1

1. Meshes. D7013E Lecture 14

Range Searching II: Windowing Queries

Predecessor. Predecessor Problem van Emde Boas Tries. Philip Bille

Binary Search Tree (2A) Young Won Lim 5/17/18

Geometric Data Structures

TREES. Trees - Introduction

Module 8: Range-Searching in Dictionaries for Points

Range Searching. Data structure for a set of objects (points, rectangles, polygons) for efficient range queries.

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Orthogonal Range Search and its Relatives

Binary Search Tree (3A) Young Won Lim 6/6/18

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Multidimensional Indexes [14]

Binary Search Tree (3A) Young Won Lim 6/4/18

kd-trees Idea: Each level of the tree compares against 1 dimension. Let s us have only two children at each node (instead of 2 d )

Geometric Data Structures

Line segment intersection (I): Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

GEOMETRIC SEARCHING PART 2: RANGE SEARCH

Lecture 3 February 23, 2012

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures

Algorithms for Memory Hierarchies Lecture 3

External Memory Algorithms for Geometric Problems. Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)

DDS Dynamic Search Trees

Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College

WINDOWING PETR FELKEL. FEL CTU PRAGUE Based on [Berg], [Mount]

CS127: B-Trees. B-Trees

Orthogonal Range Queries

CSE 530A. B+ Trees. Washington University Fall 2013

Garbage Collection: recycling unused memory

We assume uniform hashing (UH):

More B-trees, Hash Tables, etc. CS157B Chris Pollett Feb 21, 2005.

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

Computational Geometry

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Implementing Relational Operators: Selection, Projection, Join. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Advanced Set Representation Methods

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

1.2 Venn Diagrams and Partitions

Predecessor Data Structures. Philip Bille

CSL 730: Parallel Programming

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Field: We have been doing geometry eg linear programming. But in computational geometry, key difference in focus: low dimension d

Friday Four Square! 4:15PM, Outside Gates

Dynamic trees (Steator and Tarjan 83)

Trees 2: Linked Representation, Tree Traversal, and Binary Search Trees

Lecture 9 March 4, 2010

Planar Point Location

External-Memory Algorithms with Applications in GIS - (L. Arge) Enylton Machado Roberto Beauclair

CMPS 2200 Fall 2017 Red-black trees Carola Wenk

CS24 Week 8 Lecture 1

Self-Balancing Search Trees. Chapter 11

Trapezoid and Chain Methods

Remember. 376a. Database Design. Also. B + tree reminders. Algorithms for B + trees. Remember

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Computational Geometry. Lecture 17

B-Trees. Version of October 2, B-Trees Version of October 2, / 22

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces

Search Trees. Undirected graph Directed graph Tree Binary search tree

CSCI Trees. Mark Redekopp David Kempe

Algorithms. Deleting from Red-Black Trees B-Trees

n 2 ( ) ( ) + n is in Θ n logn

Geometric Data Structures

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

Why Use Binary Trees? Data Structures - Binary Trees 1. Trees (Contd.) Trees

Multidimensional Indexing The R Tree

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Computational Geometry

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

Integer Algorithms and Data Structures

Data Structures - Binary Trees 1

Augmenting Data Structures

Transcription:

Philip Bille Problem problem. Preprocess at set of points P R 2 to support report(x1, y1, x2, y2): Return the set of points in R P, where R is rectangle given by (x1, y1) and (x2, y2). Applications Relational databases. SELECT all employees between 60 and 70 years old with a montly salary between 60000 and 80000 DKr Salary (x1, y1) 80000 (x2, y2) 60000 60 70 age

1D. Preprocess a set of n points P R to support: report(x1, x2): Return the set of points in interval [x1, x2] Simplifying assumption. Only comparison-based techniques (no hashing or bittricks). Solutions? 1D 1D 1 5 7 9 11 23 26 30 31 41 48 53 66 69 71 77 1 5 7 9 11 23 26 30 31 41 48 53 66 69 71 77 1D range tree. Balanced binary tree over P in sorted order. All points stored at leaves. Internal nodes stored range of points below. Space. O(n) Preprocessing. O(n log n) Report(x1, x2): Search for predecessor of x1 + successor of x2. Traverse all nodes in between. Example. Report(20, 68) = {23, 26, 30, 31, 41, 48, 53, 66}. Time. O(log n + occ)

1D Theorem. We can solve the 1D range reporting problem in O(n) space. O(log n + occ) time for queries. O(n log n) preprocessing time. Optimal in comparison-based model. 2D Range reporting Goal. 2D range reporting with O(n log n) space and O(log n + occ) query time or O(n) space and O(n 1/2 + occ) query time. Solution in 4 steps. Generalized 1D range reporting. 2D range trees. 2D range trees with fractional cascading.. Generalized 1D Data structure. 1D range tree Tx over x-coordinate 1D range tree Ty over y-coordinate Report(x1, y1, x2, y2): Compute all points Rx in x-range. Compute all points Ry in y-range. Return Rx Ry Time?

Data structure. A 1D range tree Tx over x-coordinate. For each node v in Tx: Store a 1D range over y-coordinate for the subset of P below v.

Space. Each point stored in ~log n range trees O(n log n) space. Preprocessing time. O(n log n) Report(x1, y1, x2, y2): Search in Tx for x-range. For each node v hanging of search path within x-range: Do a 1D report query with y-range. Return the union of the results.

Time. 1D range query on x-range: O(log n) time < 2log n 1D range queries: Each uses O(log n + occ in subrange) time. in total O(log 2 n + occ) time. 2D Theorem. We can solve the 2D range reporting problem in O(n log n) space. O(log 2 n + occ) time for queries. O(n log n) preprocessing time. Do we really need the log 2 n term for queries? Can we get (optimal) O(log n) time?

Fractional Cascading Goal. 2D range reporting in O(n log n) space and O(log n) time Idea. Exploit properties of the O(log n) searches on y-range. All searches on the same y-range. Points at node v is a subset of points at parent of v. Solution in 2 steps. for binary search on arrays. on 2D range trees. Fractional Cascading Binary search on two arrays. Let A1 and A2 be two sorted arrays such that A2 A1. Goal. Implement binary search for key k on both A1 and A2. Solution 1. Do a binary search for k on A1. Do a binary search for k on A2 Challenge. Can we add some data structure so we can do it with one binary search? Fractional Cascading Solution 2. For each i store pointer to predecessor of A1[i] in A2 Binary search for k in A1. Follow pointer and locate predecessor in A2. A1 1 3 8 15 17 23 25 26 27 30 46 51 52 65 66 70 A1 1 3 8 15 17 23 25 26 27 30 46 51 52 65 66 70 A2 3 8 23 26 27 46 51 66 A2 3 8 23 26 27 46 51 66 Space. O( A1 + A2 ) Time. O(log A1 ) Binary search 1D range reporting. Generalizes to 2+ arrays.

Fractional Cascading 2D range trees need O(log n) searches on y-range. All searches on the same y-range. Points at node v is a subset of points at parent of v. we can implement searches using fractional cascading. Fractional Cascading Data structure. Store a 1D range tree Tx over x-coordinate. For each node v in Tx store a sorted array over y-coordinate for the subset of P below v. Add predecessor pointers from the array for v to the arrays for children of v. Space. O(n log n) Preprocessing. O(n log n) Fractional Cascading Report(x1, y1, x2, y2): Search in Tx for x-range. Search in root array for y-range. For each node v hanging off the search paths within the x-range: Do a 1D report query with y-range using predecessor pointers. Return the union of the results. Fractional Cascading Time. 1D range query on x-range: O(log n) time 1D range query on y-range on root array: O(log n) time Pointer walking: O(log n) time. Report points in subrange: O(occ in subrange) time. in total O(log n + occ) time.

Fractional Cascading Theorem. We can solve the 2D range reporting problem in O(n log n) space O(log n + occ) time for queries. O(n log n) preprocessing time. What can we do with only linear space? kd Trees The 2D tree (k = 2). A balanced binary tree over point set P. Recursively partition P into rectangular regions containing (roughly) same number of points. Partition by alternating horizontal and vertical lines. Each node in tree stores region and line. kd Trees Report(x1, y1, x2, y2): Traverse 2D tree starting at the root. At node v: Case 1. v is a leaf: report the unique point in region(v) if contained in range. Case 2. region(v) is disjoint from range: stop. Case 3. region(v) is contained in range: report all points in region(v). Case 4. region(v) intersects range, and v is not a leaf. Recurse left and right. l8 a l4 c d l9 l1 h i l6 l11 j l2 l1 l3 l8 a l4 c d l9 l1 h i l6 l11 j l2 l1 l3 b l2 e l10 k l l12 m l3 l13 l4 l5 l6 l7 l8 l9 l10 l11 l12 l13 g j b l2 e l10 k l l12 m l3 l13 l4 l5 l6 l7 l8 l9 l10 l11 l12 l13 g j f g n a b c d e f h i k l m n f g n a b c d e f h i k l m n Space. O(n) l5 l7 l5 l7 Preprocessing. O(n log n) Time. O(n 1/2 )

kd trees Theorem. We can solve the 2D range reporting problem in O(n) space O(n 1/2 + occ) time O(n log n) preprocessing 2D Theorem. We can solve 2D range reporting in either O(n log n) space and O(log n + occ) query time O(n) space and O(n 1/2 + occ) query time. Extensions. More dimensions. Inserting and deleting points. Using word RAM techniques. Other shapes (circles, triangles, etc.)