geosearch

geosearch - G e o m e t r ic se ar ch : O v e r v ie w G e...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Robert Sedgewick and Kevin Wayne • Copyright © 2006 • http://www.Princeton.EDU/~cos226 Geometric Algorithms Reference: Chapters 26-27, Algorithms in C, 2 nd Edition, Robert Sedgewick 2 Geometric search: Overview Types of data. Points, lines, planes, polygons, circles, . .. This lecture. Sets of N objects. Geometric problems extend to higher dimensions. ! Good algorithms also extend to higher dimensions. ! Curse of dimensionality. Basic problems. ! Range searching. ! Nearest neighbor. ! Finding intersections of geometric objects. 3 7.3 Range Searching 4 1D Range Search Extension to symbol-table ADT with comparable keys. ! Insert key-value pair. ! Search for key k. ! How many records have keys between k 1 and k 2 ? ! Iterate over all records with keys between k 1 and k 2 . Application: database queries. Geometric intuition. ! Keys are point on a line . ! How many points in a given interval ? insert B B insert D B D insert A A B D insert I A B D I insert H A B D H I insert F A B D F H I insert P A B D F H I P count G to K 2 search G to K H I
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1D Range Search Implementations Range search. How many records have keys between k 1 and k 2 ? Ordered array. Slow insert, binary search for k 1 and k 2 to find range. Hash table. No reasonable algorithm (key order lost in hash). BST. In each node x, maintain number of nodes in tree rooted at x. Search for smallest element ! k 1 and largest element " k 2 . log N N log N count insert range ordered array N R + log N hash table 1 N BST log N R + log N nodes examined within interval not touched N = # records R = # records that match 6 2D Orthogonal Range Search Extension to symbol-table ADT with 2D keys. ! Insert a 2D key. ! Search for a 2D key. ! Range search: find all keys that lie in a 2D range? ! Range count: how many keys lie in a 2D range? Applications: networking, circuit design, databases. Geometric interpretation. ! Keys are point in the plane . ! Find all points in a given h-v rectangle ? 7 2D Orhtogonal Range Search: Grid Implementation Grid implementation. [Sedgewick 3.18] ! Divide space into M-by-M grid of squares. ! Create linked list for each square. ! Use 2D array to directly access relevant square. ! Insert: insert (x, y) into corresponding grid square. ! Range search: examine only those grid squares that could have points in the rectangle. LB RT 8 2D Orthogonal Range Search: Grid Implementation Costs Space-time tradeoff. ! Space: M 2 + N. ! Time: 1 + N / M 2 per grid cell examined on average. Choose grid square size to tune performance. ! Too small: wastes space. ! Too large: too many points per grid square. ! Rule of thumb: ! N by ! N grid. Running time. [if points are evenly distributed] ! Initialize: O(N). ! Insert:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

geosearch - G e o m e t r ic se ar ch : O v e r v ie w G e...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online