Computational Geometry

Similar documents
Computational Geometry

Computational Geometry

Computational Geometry

Range Searching II: Windowing Queries

Computational Geometry

CMSC 754 Computational Geometry 1

Computing intersections in a set of line segments: the Bentley-Ottmann algorithm

Range Reporting. Range Reporting. Range Reporting Problem. Applications

WINDOWING PETR FELKEL. FEL CTU PRAGUE Based on [Berg], [Mount]

Trapezoidal Maps. Notes taken from CG lecture notes of Mount (pages 60 69) Course page has a copy

Lecture 3: Art Gallery Problems and Polygon Triangulation

Orthogonal Range Search and its Relatives

Range-Aggregate Queries Involving Geometric Aggregation Operations

Computation Geometry Exercise Range Searching II

Range Searching and Windowing

1 The range query problem

Computational Geometry

Lecture 3 February 9, 2010

Orthogonal range searching. Range Trees. Orthogonal range searching. 1D range searching. CS Spring 2009

Range Reporting. Range reporting problem 1D range reporting Range trees 2D range reporting Range trees Predecessor in nested sets kd trees

Polygon Partitioning. Lecture03

Orthogonal range searching. Orthogonal range search

HEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES

CS 532: 3D Computer Vision 11 th Set of Notes

Computational Geometry

External Memory Algorithms for Geometric Problems. Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)

Computational Geometry

Computational Geometry

Computational Geometry. Lecture 17

Lecture 15: The subspace topology, Closed sets

Planar Point Location

Sorting and Selection

External-Memory Algorithms with Applications in GIS - (L. Arge) Enylton Machado Roberto Beauclair

Data structures for totally monotone matrices

Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b

A SIMPLE APPROXIMATION ALGORITHM FOR NONOVERLAPPING LOCAL ALIGNMENTS (WEIGHTED INDEPENDENT SETS OF AXIS PARALLEL RECTANGLES)

Logarithmic-Time Point Location in General Two-Dimensional Subdivisions

Line segment intersection. Family of intersection problems

Geometric data structures:

Balanced Binary Search Trees. Victor Gao

3 Competitive Dynamic BSTs (January 31 and February 2)

Lecture 6: External Interval Tree (Part II) 3 Making the external interval tree dynamic. 3.1 Dynamizing an underflow structure

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

An Optimal Dynamic Interval Stabbing-Max Data Structure?

The Visibility Problem and Binary Space Partition. (slides by Nati Srebro)

1 Computational Geometry: Generalized (or Colored) Intersection Searching

Orthogonal Range Queries

Efficient Algorithmic Techniques for Several Multidimensional Geometric Data Management and Analysis Problems

Line Arrangement. Chapter 6

January 10-12, NIT Surathkal Introduction to Graph and Geometric Algorithms

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

Module 8: Range-Searching in Dictionaries for Points

Computational Geometry

Minimum Spanning Trees

Computational Geometry

Lecture Notes: External Interval Tree. 1 External Interval Tree The Static Version

I/O-Algorithms Lars Arge Aarhus University

Geometric Data Structures

would be included in is small: to be exact. Thus with probability1, the same partition n+1 n+1 would be produced regardless of whether p is in the inp


Chapter 6. Planar Orientations. 6.1 Numberings of Digraphs

Λέων-Χαράλαμπος Σταματάρης

1D Range Searching (cont) 5.1: 1D Range Searching. Database queries

Binary Heaps in Dynamic Arrays

Heaps Goodrich, Tamassia. Heaps 1

STRAIGHT LINE ORTHOGONAL DRAWINGS OF COMPLETE TERNERY TREES SPUR FINAL PAPER, SUMMER July 29, 2015

CS6100: Topics in Design and Analysis of Algorithms

A Discrete and Dynamic Version of Klee s Measure Problem

Lower Bound on Comparison-based Sorting

15-451/651: Design & Analysis of Algorithms November 8,,2018 Lecture #20: Powerful Arrays last changed: November 8, 2018

Point Enclosure and the Interval Tree

Heaps Outline and Required Reading: Heaps ( 7.3) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

CS 532: 3D Computer Vision 14 th Set of Notes

More about The Competition

An Optimal Algorithm for the Euclidean Bottleneck Full Steiner Tree Problem

Heaps. 2/13/2006 Heaps 1

Planarity Testing for C-Connected Clustered Graphs. Elias Dahlhaus Karsten Klein Petra Mutzel. Algorithm Engineering Report TR July 2006

Chapter 8. Voronoi Diagrams. 8.1 Post Oce Problem

Topology 550A Homework 3, Week 3 (Corrections: February 22, 2012)

COMP Analysis of Algorithms & Data Structures

Range Searching. Data structure for a set of objects (points, rectangles, polygons) for efficient range queries.

Advanced Algorithms Computational Geometry Prof. Karen Daniels. Fall, 2012

Stabbers of line segments in the plane

9.5 Equivalence Relations

GEOMETRIC SEARCHING PART 1: POINT LOCATION

Lecture-12: Closed Sets

9 Bounds for the Knapsack Problem (March 6)

Section 16. The Subspace Topology

Programming II (CS300)

13.4 Deletion in red-black trees

Heaps 2. Recall Priority Queue ADT. Heaps 3/19/14

CSE 530A. B+ Trees. Washington University Fall 2013

Average case analysis of dynamic geometric optimization

COMP Analysis of Algorithms & Data Structures

Trapezoid and Chain Methods

Approximate Nearest Line Search in High Dimensions

CPSC / Sonny Chan - University of Calgary. Collision Detection II

Optimization and approximation on systems of geometric objects van Leeuwen, E.J.

338 Copyright SIAM. Unauthorized reproduction of this article is prohibited.

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

Transcription:

Windowing queries

Windowing Windowing queries Zoom in; re-center and zoom in; select by outlining

Windowing Windowing queries

Windowing Windowing queries Given a set of n axis-parallel line segments, preprocess them into a data structure so that the ones that intersect a query rectangle can be reported efficiently

Windowing Windowing queries Given a set of n arbitrary, non-crossing line segments, preprocess them into a data structure so that the ones that intersect a query rectangle can be reported efficiently

Windowing Windowing queries Two cases of intersection: An endpoint lies inside the query window; solve with range trees The segment intersects a side of the query window; solve how?

Using a bounding box? Windowing queries If the query window intersects the line segment, then it also intersects the bounding box of the line segment (whose sides are axis-parallel segments) So we could search in the 4n bounding box sides

Using a bounding box? Windowing queries But: if the query window intersects bounding box sides does not imply that it intersects the corresponding segments

Windowing Windowing queries Current problem of our interest: Given a set of arbitrarily oriented, non-crossing line segments, preprocess them into a data structure so that the ones intersecting a vertical (horizontal) query segment can be reported efficiently

Using an interval tree? Windowing queries q q

Interval querying Given a set I of n intervals on the real line, preprocess them into a data structure so that the ones containing a query point (value) can be reported efficiently We have the interval tree, but we will develop an alternative solution

Interval querying Given a set S = {s 1,s 2,...,s n } of n segments on the real line, preprocess them into a data structure so that the ones containing a query point (value) can be reported efficiently s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8 The new structure is called the segment tree

Locus approach The locus approach is the idea to partition the solution space into parts with equal answer sets s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8 For the set S of segments, we get different answer sets before and after every endpoint

Locus approach Let p 1,p 2,...,p m be the sorted set of unique endpoints of the intervals; m 2n s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p 8 The real line is partitioned into (,p 1 ), [p 1,p 1 ],(p 1,p 2 ), [p 2,p 2 ], (p 2,p 3 ),..., (p m,+ ), these are called the elementary intervals

Locus approach We could make a binary search tree that has a leaf for every elementary interval (,p 1 ), [p 1,p 1 ],(p 1,p 2 ), [p 2,p 2 ], (p 2,p 3 ),..., (p m,+ ) Each segment from the set S can be stored with all leaves whose elementary interval it contains: [p i,p j ] is stored with [p i,p i ],(p i,p i+1 ),..., [p j,p j ] A stabbing query with point q is then solved by finding the unique leaf that contains q, and reporting all segments that it stores

Locus approach s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8 (, p 1 )(p 1, p 2 )(p 2, p 3 )(p 3, p 4 )(p 4, p 5 )(p 5, p 6 )(p 6, p 7 )(p 7, p 8 )(p 8, + ) [p 1, p 1 ] [p 2, p 2 ] [p 3, p 3 ] [p 4, p 4 ] [p 5, p 5 ] [p 6, p 6 ] [p 7, p 7 ] [p 8, p 8 ]

Locus approach p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8

Locus approach Question: What are the storage requirements and what is the query time of this solution?

Towards segment trees (p i, p i+2 ] In the tree, the leaves store elementary intervals But each internal node corresponds to an interval too: the interval that is the union of the elementary intervals of all leaves below it (p i, p i+1 ) (p i+1, p i+2 ) [p i+1, p i+1 ] [p i+2, p i+2 ] p i p i+1 p i+2

Towards segment trees (p 2, p 4 ] (p 6, + ) (p 1, p 2 ] p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8

Towards segment trees Let Int(ν) denote the interval of node ν To avoid quadratic storage, we store any segment s j as high as possible in the tree whose leaves correspond to elementary intervals More precisely: s j is stored with ν if and only if Int(ν) s j but Int(parent(ν)) s j

Towards segment trees (p i 2, p i+2 ] (p i, p i+2 ] ν s j (p i 2, p i+2 ] (p i, p i+1 ) (p i+1, p i+2 ) [p i+1, p i+1 ] [p i+2, p i+2 ] (p i, p i+2 ] Int(parent(ν)) Int(ν) p i 2 p i 1 p i p i+1 p i+2

A segment tree on a set S of segments is a balanced binary search tree on the elementary intervals defined by S, and each node stores its interval, and its canonical subset of S in a list (unsorted) The canonical subset (of S) of a node ν is the subset of segments s j for which Int(ν) s j but Int(parent(ν) s j

s 1, s 3, s 4 s 1 s 1, s 2 s 5 s 3, s 5 s 6 s 6, s 7 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1, s 2 s 3, s 4 s 5 s 6 s 7 s 8 s7, s 8 s 7, s 8 s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8

s 1, s 3, s 4 s 1 s 1, s 2 s 5 s 3, s 5 s 6 s 6, s 7 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1, s 2 s 3, s 4 s 5 s 6 s 7 s 8 s7, s 8 s 7, s 8 s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8

Question: Why are no segments stored with nodes on the leftmost and rightmost paths of the segment tree?

Query algorithm The query algorithm is trivial: For a query point q, follow the path down the tree to the elementary interval that contains q, and report all segments stored in the lists with the nodes on that path

Example query s 1, s 3, s 4 s 1 s 1, s 2 s 5 s 3, s 5 s 6 s 6, s 7 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1, s 2 s 3, s 4 s 5 s 6 s 7 s 8 s7, s 8 s 7, s 8 s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8

Example query s 1, s 3, s 4 s 1 s 1, s 2 s 5 s 3, s 5 s 6 s 6, s 7 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1, s 2 s 3, s 4 s 5 s 6 s 7 s 8 s7, s 8 s 7, s 8 s 1 s 2 s 3 s 4 s 5 s 6 s7 s 8

Query time The query time is O(logn + k), where k is the number of segments reported

Segments stored at many nodes A segment can be stored in several lists of nodes. How bad can the storage requirements get?

Segments stored at many nodes Lemma: Any segment can be stored at up to two nodes of the same depth Proof: Suppose a segment s i is stored at three nodes ν 1, ν 2, and ν 3 at the same depth from the root s i ν 1 s i ν 2 s i ν 3 parent(ν 2 ) s i

Segments stored at many nodes If a segment tree has depth O(logn), then any segment is stored in at most O(logn) lists the total size of all lists is O(nlogn) The main tree uses O(n) storage The storage requirements of a segment tree on n segments is O(nlogn)

Segments and range queries Note the correspondence with 2-dimensional range trees ν p p µ µ p p

Result Theorem: A segment tree storing n segments (= intervals) on the real line uses O(nlogn) storage, can be built in O(nlogn) time, and stabbing queries can be answered in O(logn + k) time, where k is the number of segments reported Property: For any query, all segments containing the query point are stored in the lists of O(logn) nodes

Stabbing counting queries Question: Do you see how to adapt the segment tree so that stabbing counting queries can be answered efficiently?

Back to windowing Segment tree variation Problem arising from windowing: Given a set of arbitrarily oriented, non-crossing line segments, preprocess them into a data structure so that the ones intersecting a vertical (horizontal) query segment can be reported efficiently

Idea for solution Segment tree variation The main idea is to build a segment tree on the x-projections of the 2D segments, and replace the associated lists with a more suitable data structure

Segment tree variation s 1, s 3, s 4 s 1 s 1, s 2 s 5 s 3, s 5 s 6 s 6, s 7 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1, s 2 s 3, s 4 s 5 s 6 s 7 s 8 s7, s 8 s 7, s 8 s 2 s 3 s 4 s 1 s 5 s 6 s 7 s 8

Segment tree variation s 1, s 3, s 4 s 1 s 1, s 2 s 5 s 3, s 5 s 6 s 6, s 7 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p8 s 1, s 2 s 3, s 4 s 5 s 6 s 7 s 8 s7, s 8 s 7, s 8 s 2 s 3 s 4 s 1 s 5 s 6 s 7 s 8

Segment tree variation Observe that nodes now correspond to vertical slabs of the plane (with or without left and right bounding lines), and: if a segment s i is stored with a node ν, then it crosses the slab of ν completely, but not the slab of the parent of ν the segments crossing a slab have a well-defined top-to-bottom order s j Int(ν) s j is stored at one or more nodes below ν

Segment tree variation s 1, s 3, s 4 s 5 s 5 p 3 p 4 s 3 s 4 s 1 s 5

Segment tree variation s 1, s 3, s 4 s 5 s 5 p 3 p 4 s 3 s 4 s 1 s 5

Segment tree variation Recall that a query is done with a vertical line segment q Only segments of S stored with nodes on the path down the tree using the x-coordinate of q can be answers q At any such node, the query problem is: which of the segments (that cross the slab completely) intersects the vertical query segment q?

Segment tree variation s 7 s 7 We store the canonical subset of a node ν in a balanced binary search tree that follows the bottom-to-top order in its leaves s 3 s 6 s 5 s 4 s 1 s 2 s 1 s 6 s 5 s 4 s 3 s 2 q s 6 s 5 s 4 s 3 s 2 s 1

Data structure Segment tree variation A query with q follows one path down the main tree, using the x-coordinate of q At each node, the associated tree is queried using the endpoints of q, as if it is a 1-dimensional range query The query time is O(log 2 n + k)

Data structure Segment tree variation The data structure for intersection queries with a vertical query segment in a set of non-crossing line segments is a segment tree where the associated structures are binary search trees on the bottom-to-top order of the segments in the corresponding slab Since it is a segment tree with lists replaced by trees, the storage remains O(n log n)

Result Segment tree variation Theorem: A set of n non-crossing line segments can be stored in a data structure of size O(nlogn) so that intersection queries with a vertical query segment can be answered in O(log 2 n + k) time, where k is the number of answers reported Theorem: A set of n non-crossing line segments can be stored in a data structure of size O(nlogn) so that windowing queries can be answered in O(log 2 n + k) time, where k is the number of answers reported