orthogonal range searching
play

Orthogonal range searching Input: n points in d dimensions E.g., - PowerPoint PPT Presentation

CS 5633 -- Spring 2008 Orthogonal range searching 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:


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

  2. 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. 17 43 1 17 43 1 • Internal nodes store copies of the leaves to satisfy binary search property: 6 8 12 14 26 35 41 42 59 61 6 8 12 14 26 35 41 42 59 61 • Node x stores in key [ x ] the maximum key [ x ] is the maximum key of any leaf in the left subtree of x. key of any leaf in the left subtree of x. 2/28/08 CS 5633 Analysis of Algorithms 5 2/28/08 CS 5633 Analysis of Algorithms 6 Example of a 1D range tree Example of a 1D range query x x x x 17 17 17 17 ≤ x ≤ x > x > x 8 42 8 42 8 42 8 42 1 14 35 43 1 14 14 35 43 1 14 35 43 1 14 14 35 43 17 43 17 17 43 6 12 26 41 59 6 12 12 26 26 41 59 1 17 43 1 17 17 43 6 12 26 41 59 6 12 12 26 26 41 59 1 1 6 8 12 14 26 35 41 42 59 61 6 8 8 12 12 14 14 26 26 35 35 41 41 42 59 61 6 8 12 14 26 35 41 42 59 61 6 8 8 12 12 14 14 26 26 35 35 41 41 42 59 61 key [ x ] is the maximum key of any leaf in the left subtree of x. R ANGE -Q UERY ([7, 41]) 2/28/08 CS 5633 Analysis of Algorithms 7 2/28/08 CS 5633 Analysis of Algorithms 8

  3. Pseudocode, part 1: General 1D range query Find the split node root 1D-R ANGE -Q UERY ( 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 ] split node else w ← right [ w ] // w is now the split node [ traverse left and right from w and report relevant subtrees ] 2/28/08 CS 5633 Analysis of Algorithms 9 2/28/08 CS 5633 Analysis of Algorithms 10 Pseudocode, part 2: Traverse Analysis of 1D-R ANGE -Q UERY left and right from split node Query time: Answer to range query represented 1D-R ANGE -Q UERY ( T , [ x 1 , x 2 ]) [ find the split node ] by O(log n ) subtrees found in O(log n ) time. // w is now the split node Thus: if w is a leaf • Can test for points in interval in O(log n ) time. then output the leaf w if x 1 ≤ key [ w ] ≤ x 2 else v ← left [ w ] // Left traversal • Can report all k points in interval in while v is not a leaf O(k + log n ) time. do if x 1 ≤ key [ v ] • Can count points in interval in then output the subtree rooted at right [ v ] v ← left [ v ] O(log n ) time (exercise) else v ← right [ v ] w Space: O( n ) output the leaf v if x 1 ≤ key [ v ] ≤ x 2 [ symmetrically for right traversal ] Preprocessing time: O( n log n ) 2/28/08 CS 5633 Analysis of Algorithms 11 2/28/08 CS 5633 Analysis of Algorithms 12

  4. 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? 2/28/08 CS 5633 Analysis of Algorithms 13 2/28/08 CS 5633 Analysis of Algorithms 14 2D range trees Analysis of 2D range trees Query time: In O(log 2 n) = O ( (log n ) 2 ) time, we can Idea: In primary 1D range tree of x -coordinate, represent answer to range query by O(log 2 n ) subtrees. every node stores a secondary 1D range tree based on y -coordinate for all points in the subtree Total cost for reporting k points: O ( k + (log n ) 2 ) . of the node. Recursively search within each. 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 ) 2/28/08 CS 5633 Analysis of Algorithms 15 2/28/08 CS 5633 Analysis of Algorithms 16

  5. 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. 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 ) 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 ) 2/28/08 CS 5633 Analysis of Algorithms 17

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend