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

Similar documents
Range Searching and Windowing

Computational Geometry

Computational Geometry. Lecture 17

Computational Geometry

Binary Search Trees > = 2014 Goodrich, Tamassia, Goldwasser. Binary Search Trees 1

Computational Geometry

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

CMPS 2200 Fall 2017 Red-black trees Carola Wenk

CS Fall 2010 B-trees Carola Wenk

CMPS 2200 Fall 2015 Red-black trees Carola Wenk

Computational Geometry

Range Reporting. Range Reporting. Range Reporting Problem. Applications

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 )

CS 3343 Fall 2007 Red-black trees Carola Wenk

How fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Binary Search Trees. CSE2100 DS & Algorithms 1

Orthogonal range searching. Orthogonal range search

GEOMETRIC SEARCHING PART 2: RANGE SEARCH

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

Computational Geometry

Sorting. CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk

CMSC 754 Computational Geometry 1

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

CMPS 2200 Fall 2017 B-trees Carola Wenk

Orthogonal Range Search and its Relatives

Lecture 3 February 9, 2010

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

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

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

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

CS 350 : Data Structures Binary Search Trees

Extra: B+ Trees. Motivations. Differences between BST and B+ 10/27/2017. CS1: Java Programming Colorado State University

Computational Geometry

Priority Queues. T. M. Murali. January 23, T. M. Murali January 23, 2008 Priority Queues

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

Chapter 12: Indexing and Hashing (Cnt(

Binary Trees. Recursive definition. Is this a binary tree?

Priority Queues. T. M. Murali. January 29, 2009

Linked Structures Songs, Games, Movies Part III. Fall 2013 Carola Wenk

Multi-Way Search Tree

CS 350 : Data Structures B-Trees

Priority Queues. T. M. Murali. January 26, T. M. Murali January 26, 2016 Priority Queues

Lecture 8: Orthogonal Range Searching

B-Tree. CS127 TAs. ** the best data structure ever

Algorithm Theory. 8 Treaps. Christian Schindelhauer

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

Plane Sweep Algorithms

Intro to DB CHAPTER 12 INDEXING & HASHING

Physical Level of Databases: B+-Trees

CSC212 Data Structure - Section FG

Point Enclosure and the Interval Tree

THE B+ TREE INDEX. CS 564- Spring ACKs: Jignesh Patel, AnHai Doan

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

Dynamic tables. Amortized Analysis. Example of a dynamic table. Example of a dynamic table. CS Spring 2008

Introduction to Indexing 2. Acknowledgements: Eamonn Keogh and Chotirat Ann Ratanamahatana

Chapter 10: Search Trees

Balanced Search Trees. CS 3110 Fall 2010

Spring 2017 B-TREES (LOOSELY BASED ON THE COW BOOK: CH. 10) 1/29/17 CS 564: Database Management Systems, Jignesh M. Patel 1

Chapter 11: Indexing and Hashing

Multidimensional Indexes [14]

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees

Search Trees (Ch. 9) > = Binary Search Trees 1

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

CSci 231 Homework 7. Red Black Trees. CLRS Chapter 13 and 14

Geometric Data Structures

Tree-Structured Indexes

Material You Need to Know

Cpt S 122 Data Structures. Data Structures Trees

Chapter 2: Basic Data Structures

Problem Set 5 Solutions

CS350: Data Structures Binary Search Trees

Minimum Spanning Trees

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Big Data Analytics. Special Topics for Computer Science CSE CSE April 14

Computational Geometry [csci 3250]

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

Trees. (Trees) Data Structures and Programming Spring / 28

Geometric Data Structures

CSci 231 Homework 7. Red Black Trees. CLRS Chapter 13 and 14

CSIT5300: Advanced Database Systems

Dynamic trees (Steator and Tarjan 83)

Massive Data Algorithmics

AVL Trees. (AVL Trees) Data Structures and Programming Spring / 17

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

Clustering Billions of Images with Large Scale Nearest Neighbor Search

Chapter 12: Indexing and Hashing

Friday Four Square! 4:15PM, Outside Gates

Chapter 12: Indexing and Hashing. Basic Concepts

CS350: Data Structures B-Trees

COMP 250 Fall Solution - Homework #4

Lecture 3 February 23, 2012

12 Binary Search Tree

GEOMETRIC SEARCHING PART 1: POINT LOCATION

I/O-Algorithms Lars Arge Aarhus University

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli

Chapter 12: Indexing and Hashing

Balanced Search Trees

Fractional Cascading

Augmenting Data Structures

Review implementation of Stable Matching Survey of common running times. Turn in completed problem sets. Jan 18, 2019 Sprenkle - CSCI211

Transcription:

CS 5633 -- Spring 2009 Orthogonal range searching Range Trees Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 5633 Analysis of Algorithms 1 Input: n points in d dimensions E.g., representing a database of n records each with d numeric fields Query: Axis-aligned box (in 2D, a rectangle) Report on the points inside the box: Are there any points? How many are there? List the points. CS 5633 Analysis of Algorithms 2 Orthogonal range searching Input: n points in d dimensions Query: Axis-aligned box (in 2D, a rectangle) Report on the points inside the box Goal: Preprocess points into a data structure to support fast queries Primary goal: Static data structure In 1D, we will also obtain a dynamic data structure supporting insert and delete 1D range searching In 1D, the query is an interval: First solution: Sort the points and store them in an array Solve query by binary search on endpoints. Obtain a static structure that can list k answers in a query in O(k + log n) time. Goal: Obtain a dynamic structure that can list k answers in a query in O(k + log n) time. CS 5633 Analysis of Algorithms 3 CS 5633 Analysis of Algorithms 4

1D range searching Example of a 1D range tree In 1D, the query is an interval: New solution that extends to higher dimensions: Balanced binary search tree New organization principle: Store points in the leaves of the tree. Internal nodes store copies of the leaves to satisfy binary search property: Node x stores in key[x] the maximum key of any leaf in the left subtree of x. CS 5633 Analysis of Algorithms 5 66 12 14 26 35 41 42 43 59 61 key[x] is the maximum key of any leaf in the left subtree of x. CS 5633 Analysis of Algorithms 6 Example of a 1D range tree 42 x xx > x Example of a 1D range query 42 x xx > x 14 35 43 14 35 43 66 12 26 41 43 59 66 12 26 41 43 59 66 12 14 26 35 41 42 59 61 66 12 14 26 35 41 42 59 61 key[x] is the maximum key of any leaf in the left subtree of x. CS 5633 Analysis of Algorithms 7 RANGE-QUERY([7, 41]) CS 5633 Analysis of Algorithms 8

General 1D range query root split node Pseudocode, part 1: Find the split node 1D-RANGE-QUERY(T, [x 1, x 2 ]) w root[t] while w is not a leaf and (x 2 key[w] or key[w] < x 1 ) do if x 2 key[w] then w left[w] else w right[w] // w is now the split node [traverse left and right from w and report relevant subtrees] CS 5633 Analysis of Algorithms 9 CS 5633 Analysis of Algorithms 10 Pseudocode, part 2: Traverse left and right from split node 1D-RANGE-QUERY(T, [x 1, x 2 ]) [find the split node] // w is now the split node if w is a leaf then output the leaf w if x 1 key[w] x 2 else v left[w] while v is not a leaf do if x 1 key[v] then output the subtree rooted at right[v] v left[v] else v right[v] output the leaf v if x 1 key[v] x 2 [symmetrically for right traversal] // Left traversal CS 5633 Analysis of Algorithms w Analysis of 1D-RANGE-QUERY Query time: Answer to range query represented by O(log n) subtrees found in O(log n) time. Thus: Can test for points in interval in O(log n) time. Can report all k points in interval in O(k + log n) time. Can count points in interval in O(log n) time Space: O(n) Preprocessing time: O(n log n) CS 5633 Analysis of Algorithms 12

2D range trees 2D range trees Store a primary 1D range tree for all the points based on x-coordinate. Thus in O(log n) time we can find O(log n) subtrees representing the points with proper x-coordinate. How to restrict to points with proper y-coordinate? CS 5633 Analysis of Algorithms 13 CS 5633 Analysis of Algorithms 14 2D range trees Idea: In primary 1D range tree of x-coordinate, every node stores a secondary 1D range tree based on y-coordinate for all points in the subtree of the node. Recursively search within each. 22 6/6 7/2 55 5/8 3/5 2D range tree example 2/7 1/1 Secondary trees 5/8 2/7 6/6 3/5 9/3 7/2 66 33 1/1 7 7 22 55 5/8 2/7 3/5 1/1 5 5 7 7 6/6 9/3 7/2 66 33 55 2 77 33 6 9/3 1/1 2/7 3/5 5/8 6/6 7/2 Primary tree CS 5633 Analysis of Algorithms 15 CS 5633 Analysis of Algorithms 16

Analysis of 2D range trees Query time: In O(log 2 n) = O((log n) 2 ) time, we can represent answer to range query by O(log 2 n) subtrees. Total cost for reporting k points: O(k + (log n) 2 ). Space: The secondary trees at each level of the primary tree together store a copy of the points. Also, each point is present in each secondary tree along the path from the leaf to the root. Either way, we obtain that the space is O(n log n). Preprocessing time: O(n log n) d-dimensional range trees Each node of the secondary y-structure stores a tertiary z-structure representing the points in the subtree rooted at the node, etc. Save one log factor using fractional cascading Query time: O(k + log d n) to report k points. Space: O(n log d 1 n) Preprocessing time: O(n log d 1 n) CS 5633 Analysis of Algorithms CS 5633 Analysis of Algorithms 18 Search in Subsets Given: Two sorted arrays A 1 and A, with A 1 A A query interval [l,r] Task: Report all elements e in A 1 and A with l e r Idea: Add pointers from A to A 1 : For each a A add a pointer to the smallest element b A 1 with b a Query: Find l A, follow pointer to A 1. Both in A and A 1 sequentially output all elements in [l,r]. Query: A 3 10 19 23 30 37 59 62 80 90 [15,40] A 1 10 19 30 62 80 Runtime: O((log n + k) + (1 + k)) = O(log n + k)) CS 5633 Analysis of Algorithms 19 Search in Subsets (cont.) Given: Three sorted arrays A 1, A 2, and A, with A 1 A and A 2 A Query: [15,40] A 3 10 19 23 30 37 59 62 80 90 A 1 10 19 30 62 80 A 2 3 23 37 62 90 Runtime: O((log n + k) + (1+k) + (1+k)) = O(log n + k)) Range trees: X Y 1 Y 2 Y 1 Y 2 CS 5633 Analysis of Algorithms 20

Fractional Cascading: Layered Range Tree Replace 2D range tree with a layered range tree, using sorted arrays and pointers instead of the secondary range trees. Preprocessing: O(n log n) Query: O(log n + k) d-dimensional range trees Query time: O(k + log d-1 n) to report k points, uses fractional cascading in the last dimension Space: O(n log d 1 n) Preprocessing time: O(n log d 1 n) Best data structure to date: Query time: O(k + log d 1 n) to report k points. Space: O(n (log n / log log n) d 1 ) Preprocessing time: O(n log d 1 n) CS 5633 Analysis of Algorithms 21 CS 5633 Analysis of Algorithms 22