Geometric Data Structures - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Geometric Data Structures

Description:

Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications Windowing Queries Related Application Query Image Database Windowing Queries Given ... – PowerPoint PPT presentation

Number of Views:179
Avg rating:3.0/5.0
Slides: 19
Provided by: GLAB5
Learn more at: http://www.cs.unc.edu
Category:

less

Transcript and Presenter's Notes

Title: Geometric Data Structures


1
Geometric Data Structures
  • Reading Chapter 10 of the Textbook
  • Driving Applications
  • Windowing Queries
  • Related Application
  • Query Image Database

2
Windowing Queries
  • Given a rectangular region (2D or 3D), or a
    window, the algorithm must determine the part of
    the database that lie in the window and report
    them. Data are normally not points, but line
    segments, polygons, etc.
  • 2D Windowing navigation using a map or an
    electronic GIS circuit-board layout, etc.
  • 3D Windowing view frustrum culling viewing a
    complex CAD/CAM model by zooming in to a small
    portion, etc.

3
Orthogonal Window Queries
  • Let S be a set of n axis-parallel line segments.
    A query asks for the segments intersecting a 2D
    query window, W xx x yy
  • Most cases, the segment has at least one point
    inside of W. We can find such segments by
    performing a range query with W in the set of 2n
    endpoints of the segments in S, by using a 2D
    range tree T. 2D range tree can answer a range
    query in O(log2n k) time query time can be
    improved to O(logn k) by fractional cascading.
  • Find segments that intersect W twice either at
    the left and right edges or top and bottom edges.
    This reduces to finding horiz. (v) segments
    intersecting a vert. (h) line.

4
Classification of Segments w.r.t. xmid
  • An interval xx contains l (xqx) iff x ?
    qx ? x
  • We can classify a set of segments w.r.t to xmid
  • Imid those containing xmid
  • Ileft those complete lie to the left cannot
    intersect l
  • Iright those complete lie to the right cannot
    intersect l
  • Check Imid to find intersecting segments with l
  • Store the intervals in 2 sorted lists
    increasing left endpoints and decreasing right
    endpoints
  • qx can be contained in an interval if its also
    contained in all its predecessors in the sorted
    list
  • We can simply walk along sorted lists reporting
    intervals stop when we encounter I s.t. qx ? I

5
Interval Trees
  • If I 0, then the interval tree is a leaf
  • Otherwise, let xmid be the median of the
    endpoints of the intervals, let Ileft
    xjxj ? I xj lt xmid ,
  • Imid xjxj ? I xj ? xmid
    ? xj ,
  • Iright xjxj ? I xmid lt xj .
  • The interval trees consists of a root node v
    storing xmid.
  • The set Imid is stored twice once in a list
    Lleft(v) that is stored on the left endpoints of
    the intervals, once in a list Lright(v) that is
    stored on the right endpoints of intervals
  • The left subtree of v is an interval tree for
    Ileft
  • The right subtree of v is an interval tree for
    Iright

6
ConstructIntervalTree(I)
  • Input A set I of intervals on the real line.
  • Output The root of an interval tree for I .
  • 1. if I 0
  • 2. then return an empty leave
  • 3. else Create a node v. Compute xmid, the
    median of the set of interval
  • endpoints, and store xmid with
    v.
  • 4. Compute Imid and construct two
    sorted lists for Imid a list Lleft(v)
  • sorted on left endpoint a list
    Lright (v) sorted on right endpoint.
  • Store these two lists at v.
  • 5. lc(v) ? ConstructIntervalTree(Ileft)
  • 6. rc(v) ? ConstructIntervalTree(Iright)
  • 7. return v

7
QueryIntervalTree(v, qx)
  • Input The root v of an interval tree and a query
    point qx
  • Output All intervals that contain qx
  • 1. if v is not a leaf
  • 2. then if qx lt xmid(v)
  • 3. then Walk along the list
    Lleft(v), starting at the
  • interval with the
    leftmost endpoint, reporting
  • all the intervals
    that contain qx. Stop as soon
  • as an interval does
    not contain qx.
  • 4. QueryIntervalTree(lc(v), qx)
  • 5. else Walk along the list
    Lright(v), starting at the
  • interval with the
    rightmost endpoint, reporting
  • all the intervals
    that contain qx. Stop as soon
  • as an interval does
    not contain qx.
  • 6. QueryIntervalTree(rc(v), qx)

8
Algorithm Analysis
  • An interval tree for a set I of n intervals uses
    O(n) storage, has depth O(logn) and can be built
    in O(n log n) time. Using the interval tree we
    can report all intervals containing a query point
    in O(k log n) time, where k is no. of reported
    intervals.
  • Let S be a set of n horizontal segments in the
    plane. The segments intersecting a vertical
    query segment can be reported in O(log2n k)
    time with a data structure of O(n log n) storage,
    where k is the number of reported segments. The
    structure can be built in O(n log n) time.
  • Let S be a set of n axis-parallel segments in the
    plane. The segments intersecting an
    axis-parallel rectangular query window can be
    reported in O(log2n k) time with a data
    structure of O(n log n) storage, where k is
    number of reported segments. The structure can
    be built in O(n log n) time.

9
Motivation for Priority Search Trees
  • Replacing RangeTrees A 2d rectangle query on P
    asks for points in P lying inside a query window
    (-?qx x qyqy. Use ideas from 1d range
    query.
  • Use a heap to answer 1d query if px? (-?qx
    and partition using the y-coordinates.
  • Root of the tree stores the point with minimum
    x-value and the remainder is partitioned into 2
    equal sets.
  • The 2 sets are partitioned into sets above
    below
  • Construct the tree recursively

10
Priority Search Trees
  • If P 0, then the priority search tree is an
    empty leaf
  • Otherwise, let pmin be the point in P with the
    smallest x-coordinate and ymid be the y-median of
    the rest in P. Let
  • Pbelow p ? P\pmin py lt ymid ,
  • Pabove p ? P\pmin py gt ymid .
  • The priority search trees consists of a root node
    v where the point p(v) pmin and the value y(v)
    ymin are stored.
  • The left subtree of v is a priority search tree
    for Pbelow
  • The right subtree of v is a priority search tree
    for Pabove

11
ReportInSubTree(v, qx)
  • InputThe root v of a subtree of a priority
    search tree and a value qx
  • Output All points in the subtree with
    x-coordinate at most qx
  • 1. if v is not a leaf and (p(v))x ? qx
  • 2. then Report p(v)
  • 3. ReportInSubTree(lc(v), qx)
  • 4. ReportInSubTree(rc(v), qx)

12
QueryPrioSearchTree(T,(-?qxxqyqy)
  • Input A priority search tree and a range
    unbounded to the left
  • Output All points lying in the range
  • 1. Search with qy and qy in T. Let vsplit be
    node where 2 search paths split
  • 2. for each node v on the search path of qy or
    qy
  • 3. do if p(v) ? (-?qxxqyqy then report
    p(v)
  • 4. for each node v on the search path of qy in
    the left subtree of vsplit
  • 5. do if the search path goes left at v
  • 6. then ReportInSubtree(rc(v), qx)
  • 7. for each node v on the search path of qy in
    the right subtree of vsplit
  • 8. do if the search path goes right at v
  • 9. then ReportInSubtree(lc(v), qx)

13
Algorithm Analysis
  • A priority search tree for a set P of n points in
    the plane uses O(n) storage can be built in O(n
    log n) time. Using the priority search tree we
    can report all points in a query range of the
    form (-?qx x qyqy in O(k log n) time,
    where k is the number of reported points.

14
Segment Tree Data Structures
  • The skeleton of the segment tree is a balanced
    binary tree T. The leaves of T correspond to the
    elementary intervals induced by the endpoints of
    the intervals in I in an ordered way the
    leftmost leaf corresponds to the leftmost
    elementary interval, and so on. The elementary
    interval corresponding to leaf u is denoted
    Int(u).
  • The internal nodes of correspond to intervals
    that are the union of elementary intervals the
    interval Int(v) corresponding to node v is the
    union of the elementary intervals Int(u) of the
    leaves in the subtree rooted at v. (implying
    Int(v) is the union of its two children)
  • Each node or leaf v in T stores the interval
    Int(v) and a set I(v)? I of intervals (e.g. in a
    linked list). This canonical subset of node v
    contains the intervals xx?I s.t.
    Int(v)?xx Int(parent(v))?xx
  • (See the diagrams in class)

15
QuerySegmentTree(v, qx)
  • InputThe root v of a (subtree of a) segment tree
    and a query point qx
  • Output All intervals in the tree containing qx
  • 1. Report all the intervals in I(v)
  • 2. if v is not a leaf
  • 3. then if qx ? Int(lc(v))
  • 4. then QuerySegmentTree(lc(v),
    qx)
  • 5. else QuerySegmentTree(rc(v), qx)

16
Constructing Segment Trees
  • Sort the endpoints on the intervals in I in O(n
    log n) time. This gives elementary intervals.
  • Construct a balanced binary tree on the
    elementary intervals determine for each node v
    of the tree the interval Int(v) it represents.
  • Compute the canonical subsets by inserting one
    interval at a time into T. (See the next
    procedure)

17
InsertSegmentTree(v, xx)
  • Input The root of a (subtree of a) segment tree
    and an interval
  • Output The interval will be stored in the
    subtree
  • 1. if Int(v) ? xx
  • 2. then store xx at v
  • 3. else if Int(lc(v)) ? xx ? 0
  • 4. then InsertSegmentTree(lc(v), qx)
  • 5. if Int(rc(v)) ? xx ? 0
  • 6. then InsertSegmentTree(rc(v), qx)

18
Algorithm Analysis
  • A segment tree for a set I of n intervals uses
    O(n log n) storage and can be built in O(n log
    n). Using the segment tree we can report all
    intervals that contain a query point in O(log n
    k) time, where k is the number of reported
    intervals.
  • Let S be a set of n segments in the plane with
    disjoint interiors. The segments intersecting an
    axis-parallel rectangular query window can be
    reported in O(log2nk) time with a data structure
    that uses O(n log n) storage, where k is the
    number of reported segments. The structure can
    be built in O(n log n) time.
Write a Comment
User Comments (0)
About PowerShow.com