1 / 72

Geometric Algorithms and Data Structures

Geometric Algorithms and Data Structures. Prof. Neeraj Suri Andreas Johansson Constantin Sarbu Abdelmajid Khelil. Outline. Introduction Geometric Data Structures Quadtree Region quadtree Point quadtree K-d tree Strip tree K-d trie Binary trie Multidimensional Data Z-Order

Download Presentation

Geometric Algorithms and Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Geometric Algorithms and Data Structures Prof. Neeraj Suri Andreas Johansson Constantin Sarbu Abdelmajid Khelil

  2. Outline • Introduction • Geometric Data Structures • Quadtree • Region quadtree • Point quadtree • K-d tree • Strip tree • K-d trie • Binary trie • Multidimensional Data • Z-Order • Multidimensional data • Data mining

  3. Geometric Problems (1) • Algorithmic geometry: Study of the algorithmic complexity of elementary geometric problems • Geometric problems: Are often abstract formulations of practical problems (similar to graph theory) • Some geometric problems and their interpretation: • Given a set of points in the plane. Find all the points within a rectangle • „Clipping“ in VR • Find tuples in a database with values within given bounds for attributes A1 and A2 • Generalization for searching in a k-dimensional field (all points contained in a k-dimensional field)

  4. Geometric Problems (2) • Given a set of rectangles in the plane. Find all pairwise intersecting rectangles • Correctness test at designing Very Large Scale Integration (VLSI), chip layers as rectangles • Given a set of 3-dimensional objects (compounds). Find pair wise intersecting objects • Ensuring the rule distance resp. the safety margin in CAD • Given a set of rectangles in the plane. Find the slice plane. • Geographic Information Systems (GIS), approximation of generic forms through rectangles, determining areas with specific properties on distinct maps (e.g. find regions which are sandy (map 1), wet (map 2), and between 200 and 300 m altitude (elevation map))

  5. Geometric Problems (3) • Given a set of polyhedrons in space. Determine the edges or portion of edges that are visible or hidden from a viewpoint. • Computation of a realistic view of a 3-dimensional scene • Determining the coverage area of a transmitter, the area with no reception • Given a set of points in a k-dimensional space and a query-point P. Find the point S closest to P. • Voice recognition: A spoken word is characterized by features and compared with the vocabulary (point set in a k-dimensional space).

  6. Classification of Geometric Problems • 2 classes of problems: • Set problems: Compute the property of a set of objects S you’re interested in. • E.g. the outline of the area covered by S • Search problems: Given a set of objects S and a query-object q. Find all objects in S that have a specific relation with q. • Set problems are often reducible to search problems • E.g. Plane-Sweep algorithms reduce a k-dimensional set problem to a (k-1)-dimensional search problem • Search problems are solved by organizing S with the aid of appropriate data structures and indexing

  7. First Problem • How do we efficiently represent this figure?

  8. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 0 Representing Figures (1) • How about a matrix representation? Black = 1, empty = 0  Not very effective

  9. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Representing Figures (2) • Idea: represent areas, not points • Now represent the areas using another structure • Quadtreesdo this

  10. Overview of Quadtrees • Quadtree is a generic term • Quadtree: A class of hierarchical data structures that are based on recursive decomposition of space • Differentiation is possible based on: • Data type represented by the Quadtree : Point data, regions, curves, surfaces, and volumes • Principle of decomposition: regular vs. input-driven • Resolution: Fixed vs. variable number of decomposition steps • Examples: • Region quadtree • Point quadtree • Literature: • Samet, H.; “The Quadtree and Related Hierarchical Data Structures”, ACM Comp. Surveys, Vol. 16, No. 2, June 1984 (available from ACM DL)

  11. Region Quadtree • Successive subdivision of the image array into 4 equal-sized quadrants. • Basic idea: • Figure as an image array, i.e. every pixel of the figure has a value of 1, all other pixels have a value of 0 • The entire area (image array) is subdivided into 4 equal-sized quadrants (usually 2k dimensional) • Upon each division one has to check if the image array of a quadrant is homogeneous (i.e. only 1s or only 0s) • homogeneous  no further subdivision • heterogeneous further subdivisions until homogeneous (possibly single pixels)

  12. NW NE N W E SW SE S Region Quadtree: Terminology

  13. 0 1 0 Region Quadtree: Terminology • Leaf nodes are said to be either BLACK or WHITE • Non-leaf nodes are said to be GREY GREY NW SE NE SW BLACK 1 0 0 1 WHITE

  14. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Region Quadtree: Example Step1

  15. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Region Quadtree : Example Step2

  16. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Region Quadtree : Example Step3

  17. Region Quadtree: Set Operations • Quadtrees are especially useful for performing set operations • Overlap (intersection) • Overlays (union) • Example: • From data provided on forests, grassland, fields, nature reserve and polder, identify which areas are in agricultural use (typical overlay problem)

  18. Overlays with Quadtrees: Example

  19. Overlays with Quadtrees: Algorithm (1) Traverse top-down quadtree QT1 beginning with root and compare with the corresponding node in quadtree QT2 if the node in QT1 is BLACK, then the corresponding node in the resulting quadtree is also BLACK if the node in QT1 is WHITE, then the node in the resulting quadtree is set to the node in QT2 if the node in QT1 is GREY, then set the node in the resulting quadtree to GREY if QT2 is GREY GREY if QT2 is WHITE BLACK if QT2 is BLACK if both nodes are gray, the algorithm returns after processing the next level to consolidate if necessary.

  20. Overlays with Quadtrees: Algorithm (2) Decision Table: 1) A check for a merger need to be performed to determine if all 4 sons are BLACK. Example:

  21. Intersection with Quadtrees (Example)

  22. Intersection with Quadtrees: Algorithm (1) Traverse top-down quadtree QT1 beginning with root and compare with the corresponding node in quadtree QT2 if the node in QT1 is BLACK and the node in QT2 is BLACK, then set the corresponding node in the resulting QT to BLACK if the node in QT1 or QT2 is WHITE, then the resulting node is WHITE if the node in QT1 is GREY, then set the node to GREY if QT2 is also GREY WHITE if QT2 is WHITE GREY if QT2 is BLACK if both nodes are grey, the algorithm returns after processing the next level to consolidate if necessary.

  23. Intersection with Quadtrees: Algorithm (2) Decision Table: 1) A check for a merger need to be performed to determine if all 4 sons are WHITE. Example:

  24. Complexity Analysis • Complexity is proportional to the number of nodes in the quadtree • best case: whole area unicolored (1 node) • worst case: “Salt and Pepper”, i.e. all inner nodes are grey, need to go down to pixel level (depends on the resolution)

  25. Point-Quadtree: Definition • Point data • 2-D points can be stored and indexed in a point-quadtree • A point-quadtree splits the space into 4 quadrants at the insertion point • The insertion order is thus important (it determines the structure of the tree)

  26. (0,100) (100,100) (35,40) Chicago (5,45) Denver (50,10) Mobile (80,65) Buffalo (60,75) Toronto (25,35) Omaha (90,5) Miami (85,15) Atlanta (0,0) (100,0) Point-Quadtree (Example) Insertion order: Chicago, Mobile, Toronto, Buffalo, Denver, Omaha, Atlanta, Miami

  27. (0,100) (100,100) (60,75) Toronto (80,65) Buffalo (50,10) Mobile (5,45) Denver (35,40) Chicago (25,35) Omaha (85,15) Atlanta (90,5) Miami (0,0) (100,0) Point-Quadtree (Example) Insertion order: Chicago, Mobile, Toronto, Buffalo, Denver, Omaha, Atlanta, Miami Chicago Toronto Omaha Denver Mobile Atlanta Buffalo Miami

  28. (0,100) (100,100) Chicago Toronto Omaha Denver Mobile (50,10) Mobile (80,65) Buffalo (35,40) Chicago (5,45) Denver (60,75) Toronto Atlanta Buffalo Miami (25,35) Omaha (90,5) Miami (85,15) Atlanta (0,0) (100,0) Point-Quadtree (Search Example) „find all points (records) within a given distance from another point (record)” Find all the cities, at most 8 units from the point (83,10)

  29. (100,100) (0,100) (5,45) Denver (80,65) Buffalo (60,75) Toronto (35,40) Chicago (25,35) Omaha (85,15) Atlanta (50,10) Mobile (90,5) Miami (0,0) (100,0) Point-Quadtree (Search Example) Find all the cities, at most 8 units from the point (83,10) • The root is (35,40)  NW, NE, SW can be ignored • Next is Mobile (50,10)  NW and SW can be ignored • Are Atlanta or Miami within 8? • Solutions based on approximations with rectangles (bounding box), can contain negative reports • Exact solution with a circle

  30. Search in Point-Quadtrees • Especially suitable for search problems of the following type: “find all points (records) within a given distance from another point (record)” • Point Quadtrees are quite efficient for 2 dimensions. In k > 2 dimensions however, Point Quadtrees have a large branching factor and thus contain many NULL-pointers Chicago Toronto Omaha Denver Mobile Atlanta Buffalo Miami

  31. K-d Trees • k-dimensional point data • We want to avoid the large fan-out of point quadtree • Quadtrees (22=4-way split) • Octrees (23=8-way split) • In general: 2k-way split • A k-d tree is a binary search tree with the distinction that at each level, a different coordinate (dimension) is tested to determine the direction of the branch • 2-way split • Node consists of • 2 child pointers • Name • Key

  32. K-d Tree: Basic Idea Construct a binary Tree • At each step, choose one of the coordinates as a basis of dividing the rest of the points • For example, at the root, choose x as the basis • Like binary search trees, all items to the left of root will have the x-coordinate less than that of the root • All items to the right of the root will have the x-coordinate greater than (or equal to) that of the root • Choose y as the basis for discrimination for the root’s children • Choose x again for the root’s grandchildren

  33. Chicago x x<xchicago x≥xchicago y Denver Mobile y<ymobile y≥ymobile x Omaha Miami Toronto (5,45) Denver (35,40) Chicago (50,10) Mobile (80,65) Buffalo (60,75) Toronto (25,35) Omaha y Buffalo (90,5) Miami (85,15) Atlanta x Atlanta K-d Tree: Example Insertion order: Chicago, Mobile, Toronto, Buffalo, Denver, Omaha, Atlanta, Miami Alternation of discriminator K-d tree (0,100) (100,100) (0,0) (100,0) Fewer NULL pointers!

  34. Adaptive k-d Tree • Like k-d tree, but • Division is between (not on) data points. • Division not by alternating the discriminator, but according to the dimension with the maximum spread (max-min). • Balanced k-d Tree • Internal nodes contain only split coordinates and their value (e.g. X=30) • The records are stored at the terminal nodes (leaves) • Insertion of one record requires rebuilding the tree ( Static structure ) • Deletion of one record is highly complex • Search is like k-d tree

  35. (0,100) (50,10) Mobile (60,75) Toronto (80,65) Buffalo (5,45) Denver (35,40) Chicago (25,35) Omaha 55,x (90,5) Miami (85,15) Atlanta 30,x 40,y (0,0) (100,0) 15,x 70,x 25,y 10,y Denver (5,45) Omaha (25,35) Mobile (50,10) Chicago (35,45) Miami (90,5) Atlanta (85,15) Toronto (60,75) Buffalo (80,65) Exampleadaptive k-d tree(k=2) (100,100)

  36. Comparison • Region Quadtree • parallelizable • Point Quadtree: • parallelizable, dynamic • K-d Tree: • Not easily parallelizable, dynamic, better sequential data structure • Adaptive k-d Tree: • Not easily parallelizable, static, balanced, optimized search

  37. Selected as splitting point for A, since Wl> Wr Root strip Wl Q P Wr B C D E A Splitting point for C Curvilinear Data: Strip Tree (Example) Basic idea: Represent the curve by strips enclosing portions of it • Strips become successively thinner • The splitting finishes when all strips are thinner than a predefined value Strip Tree:

  38. Strip Tree: Algorithm • Recursive Splitting • Join the endpoints of the curve (i.e. P and Q) • The root corresponds to a rectangle enclosing the curve and whose sides are parallel to line PQ • The next split point • Lies on the curve and on one side of the strip rectangle • Has maximum distance to line PQ • Node Structure • The node is an 8-tuple and contains • 2 pairs of X,Y coordinates (the diagonal endpoints) • The strip width on each side of the line connecting the endpoints • Pointers to the 2 sons

  39. Representation of Arbitrary Curves • Curves are well represented by chains, however indexing them is difficult • A strip-tree is a quadtree variant for representing arbitrary curves by hierarchical decomposition • Useful in applications that involve search and set operations

  40. Trees and Tries • We have seen (normal) trees for storing figures • We can also use Tries! • Tries store the key “along the way”

  41. L R D U L L R R D U D U D U L R RDRU D U D U • Key stored along the path from the root, Ex: “RDRU” • The complete keys are located at the leaves Kd-Tries: Example L: left R: right D: Down U: Up X dim Y dim

  42. 0 1 0 1 100101 Binary Tries A binary trie is a binary tree, whereby left sons correspond to a “0” at the corresponding position in the key, and right sons correspond to a “1” 0 1 0 1 0 0 1 1 0 1 0 1 0 1 0 1

  43. Geometric Interpretation of the Binary Trie • A trie compresses a 1-dimensional space with 2daddresses through coding to a string with d characters • In previous example: d=3+3=6 • The root represents the complete space • Left son (first character = 0) represents the lower half of the search space • Right son (first character = 1) represents the upper half of the search space.

  44. 111 110 101 100 0 1 0 1 Y0Y1Y2 011 010 001 000 000 001 010 011 100 101 110 111 X0X1X2 Binary y coordinate of the cell 100101 Binary x coordinate of the cell Binary Tries, Revisited In 2D each key is a pair of bit sequences (x,y) 0 1 0 1 0 0 1 1 0 1 0 1 0 1 0 1 The path to the key is composed of bits that are taken from the x and y coordinates on a rotating basis

  45. Observations • Kd-trie splits by rotating x and y coordinates • A kd-trie is unique for a given set of keys • Trie structure does not depend on the insertion order • Geometric kd-tries generate a total order of the search space • Two points P1 and P2 in the kd-Space will always have the same order

  46. Building a Linear Order • Given a 2D grid how • (1) to find a linear order for the cells of the grid such that cells close together in space are also (as far as possible) close to each other in the linear order, and • (2) to define this order recursively for a grid that is obtained by a hierarchical subdivision of space. • The most popular solution is Bit interleaving (Z-Order)

  47. Z-Order • Addresses in a 2-dimensional space are identified by pairs (x,y) of values • Each x and y value is a sequence of d bits • This results in a grid with 2d x 2d cells • How to build the addresses using bit interleaving? 0 0 0 0 1 1 1 1 111 0 0 0 0 1 1 1 1 110 Start with a vertical split for X0 (Z=X0) 0 0 0 0 1 1 1 1 101 0 0 0 0 1 1 1 1 100 Y0Y1Y2 0 0 0 0 1 1 1 1 011 0 0 0 0 1 1 1 1 010 0 0 0 0 1 1 1 1 001 0 0 0 0 1 1 1 1 000 000 001 010 011 100 101 110 111 X0X1X2

  48. Z-Order Horizontal split for Y0 (Z=X0Y0) 01 01 01 01 11 11 11 11 111 01 01 01 01 11 11 11 11 110 01 01 01 01 11 11 11 11 101 01 01 01 01 11 11 11 11 100 Y0Y1Y2 00 00 00 00 10 10 10 10 011 00 00 00 00 10 10 10 10 010 00 00 00 00 10 10 10 10 001 00 00 00 00 10 10 10 10 000 000 001 010 011 100 101 110 111 X0X1X2

  49. Z-Order Vertical split for X1 (Z=X0Y0X1) 010 010 011 011 110 110 111 111 111 010 010 011 011 110 110 111 111 110 010 010 011 011 110 110 111 111 101 010 010 011 011 110 110 111 111 100 Y0Y1Y2 000 000 001 001 100 100 101 101 011 000 000 001 001 100 100 101 101 010 000 000 001 001 100 100 101 101 001 000 000 001 001 100 100 101 101 000 000 001 010 011 100 101 110 111 X0X1X2

  50. Z-Order Horizontal split for Y1 (Z=X0Y0X1Y1) 0101 0101 0111 0111 1101 1101 1111 1111 111 0101 0101 0111 0111 1101 1101 1111 1111 110 0100 0100 0110 0110 1100 1100 1110 1110 101 0100 0100 0110 0110 1100 1100 1110 1110 100 Y0Y1Y2 0001 0001 0011 0011 1001 1001 1011 1011 011 0001 0001 0011 0011 1001 1001 1011 1011 010 0000 0000 0010 0010 1000 1000 1010 1010 001 0000 0000 0010 0010 1000 1000 1010 1010 000 000 001 010 011 100 101 110 111 X0X1X2

More Related