1 / 58

INTERVAL TREE & SEGMENTATION TREE

INTERVAL TREE & SEGMENTATION TREE. Juho Lee, UiTae Kim. UiTae Kim. Interval tree. Can we load them all?. Or even should we?. Windowing Query. Query for finding objects in rectangular region. Let’s consider roads as line segments. Let’s make the example even easier…. Orthogonal.

nixie
Download Presentation

INTERVAL TREE & SEGMENTATION TREE

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. INTERVAL TREE & SEGMENTATION TREE Juho Lee, UiTae Kim

  2. UiTae Kim Interval tree

  3. Can we load them all? Or even should we?

  4. Windowing Query • Query for finding objects in rectangular region Let’s consider roads as line segments

  5. Let’s make the example even easier… Orthogonal Only two possible orientations Axis-parallel

  6. Data structure • S: set of n axis-parallel line segments • Query: find all line segments in S, intersecting W. • W:=[x:x’] X [y:y’] • We need a data structure for solving this window query efficiently

  7. Check segment as marked 2-D range search Query time: Storage: Entirely inside Intersects once Intersects twice (partially) overlaps boundary

  8. Lemma 10.1 • Let S be a set of n axis-parallel line segments in the plane. The segments that have at least one endpoint inside an axis-parallel query window Wcan be reported in O(logn+k) time with a data structure that uses O(nlogn) storage and preprocessing time, where k is the number of reported segments.

  9. Now problem is reduced to… Checking whether the given line segments intersects ℓ: intersects ℓ iff Now the problem becomes 1-D intersection test

  10. Finding intersection in 1-D •  closed set of intervals •  median of 2n endpoints • If , we don’t need to consider about the segments placed to the right of .

  11. Finding intersection in 1-D • Construct binary tree • Root(or interim node): • Left child: Tree made of line segments placed to the left of • Right child: Tree made of line segments placed to the right of

  12. Finding intersection in 1-D • Construct binary tree Make tree recursively

  13. Finding intersection in 1-D • Construct binary tree is in interval iff  can be done easily if we have sorted list

  14. Interval tree • If , then the interval tree is leaf • Otherwise, let root be •  forms left subtree • : stored twice • : sorted from left to right • : sorted from right to left •  forms right subtree

  15. Interval tree

  16. Lemma 10.2 • An interval tree on a set of n intervals uses O(n) storage and has depth O(logn).

  17. Lemma 10.2 • pf) Depth part is trivial, since we are storing 2n endpoints in a binary tree. O(log n)

  18. Lemma 10.2 • pf) For storage bound, note that are all disjoint. • Thus, each segments are stored only twice, one for , and the other for • Hence, the storage bound is O(n). • The tree uses O(n) also.

  19. Algorithm: ConstructIntervalTree • ConstructIntervalTree(I) • Input: A set I of intervals on the real line • Output: The root of an interval tree for I

  20. Algorithm: ConstructIntervalTree 1. if 2. then return an empty leaf 3. elseCreate a node ν. Compute , the median of the set of interval endpoints, and store with ν. 4. Compute and construct two sorted lists for : a list sorted on left endpoint and a list sorted on right endpoint. Store these two lists at ν. 5. lc(ν)← ConstructIntervalTree() 6. rc(ν)← ConstructIntervalTree() 7. returnv

  21. Algorithm: ConstructIntervalTree • Finding median: O(n), but better to keep sorted list. O(nlogn) • Let ,then creating takes • Each step takes • Using similar arguments in Lemma 10.2, .

  22. Lemma 10.3 • An interval tree on a set of n intervals can be built in O(nlogn) time.

  23. Algorithm: QueryIntervalTree • QueryIntervalTree(v, ) • Input: The root v of a interval tree and a query point • Output: All intervals containing

  24. Algorithm: QueryIntervalTree 1. ifν is not a leaf 2. then if< 3. thenWalk along the list , starting at the interval with the leftmost endpoint, reporting all the intervals that contain . Stop as soon as an interval does not contain . 4. QueryIntervalTree(lc(ν),) 5. elseWalk along the list , starting at the interval with the rightmost endpoint, reporting all the intervals that contain . Stop as soon as an interval does not contain . 6. QueryIntervalTree(rc(ν),)

  25. Algorithm: QueryIntervalTree • For each step, , where is the # of pts reporting • We go through steps, and . • Query time is

  26. Theorem 10.4 • An interval tree for a set I of n intervals uses O(n) storage and can be built in O(nlogn) time. Using the interval tree we can report all intervals that contain a query point in O(logn+k) time, where k is the number of reported intervals.

  27. Interval Tree Query time: Storage: 2-D range search Query time: Storage: Entirely inside Intersects once Intersects twice (partially) overlaps boundary

  28. Extend query to segment • Let be the set of horizontal segments in . • Query becomes . • looks like .

  29. Extend query to segment • Recursively traveling through the left(right) subtree is still correct

  30. Extend query to segment • However, treat for the is no longer correct Nothing but a range query [)if

  31. Extend query to segment • However, treat for the is no longer correct • Perform range search for the left(right) endpoints • Query is ] (or [) • Uses storage, query time

  32. Data structure • Main structure: interval tree on x-intervals of segments • Instead of , we have range search tree .

  33. Data structure Replaced to range tree

  34. Data structure • Range tree takes , instead of . • Total time for each step becomes • Storage complexity becomes , since range tree dominates the main interval tree • Preprocessing time remains

  35. Theorem 10.5 • Let S be a set of n horizontal segments in the plane. The segments intersecting a vertical query segment can be reported in time with a data structure that uses storage, where k is the number of reported segments. The structure can be built in time.

  36. Lemma 10.1 • Let S be a set of n axis-parallel line segments in the plane. The segments that have at least one endpoint inside an axis-parallel query window Wcan be reported in O(logn+k) time with a data structure that uses O(nlogn) storage and preprocessing time, where k is the number of reported segments.

  37. Corollary 10.6 • 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 time with a data structure that uses storage, where k is the number of reported segments. The structure can be built in time.

  38. Summary • Query Time: • Storage: • Preprocessing:

  39. Jooho Lee Segment Tree

  40. Problem • Given n segments, find intervals which contain qx. • Let solve it with BST. qx

  41. Elementary Intervals (): Open Interval[]: Closed Interval • At most 4n+1 elementary Intervals.2n(end points)+2n(segments)+1(right side) { (p5:p6) (p3:p4) (p1:p2) (p6:+∞) } (-∞:p1) (p2:p3) (p4:p5) [p4:p4] [p3:p3] [p5:p5] [p6:p6] [p2:p2] [p1:p1] =Elementary Intervals I

  42. BST of Elementary Intervals • Height of BST: O(log(4n+1))=O(log n) u [p3:p3] [p2:p2] (p3:p4) (p1:p2) (p2:p3) (-∞:p1) [p1:p1] (p1:p2) (p3:p4) (-∞:p1) (p2:p3) (p4:∞) [p4:p4] [p3:p3] [p2:p2] [p1:p1] (p4:∞) [p4:p4] Let Int(u) corresponding Interval with u.Int(u) is (p1:p2) interval.

  43. BST of Elementary Intervals • At leaf node u, Store interval I containing Int(u). • Query time: log(n)+k1.find the leaf interval containing qx2.report all intervals stored at the corresponding leaf node. • But Storage can be quadratic..O(n2) u [p3:p3] [p2:p2] (p3:p4) (p1:p2) (p2:p3) (-∞:p1) [p1:p1] (p4:∞) [p4:p4]

  44. Qaudratic Storage Example storages for open leaf intervals :0 1 2 . . . . . . . . .N-1 N N-1 . . . . . . . . 2 1 0 Sum of storages for open leaf intervals is more than N(N+1)/2!

  45. Idea • Internal node w = union of elemental intervals of leaves in the sub-tree(w)! • Segment Tree v u Int(u) Int(v) [p3:p3] [p2:p2] (p3:p4) (p1:p2) (p2:p3) (-∞:p1) [p1:p1] (p1:p2) (p3:p4) (-∞:p1) (p2:p3) (p4:∞) [p4:p4] [p3:p3] [p2:p2] [p1:p1] (p4:∞) [p4:p4]

  46. Which interval is contained at node v? • Each node v store the Interval such that • If ,[x:x`] is stored at parent(v) or parentn(v)

  47. Storage in Segment Tree

  48. Construction of Segment Tree

More Related