Segment tree and Interval Tree

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Interval Trees Store intervals of the form [li,ri], li <= ri.
Orthogonal range searching. The problem (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
An Optimal Dynamic Interval Stabbing-Max Data Structure? Pankaj K. Agarwal, Lars Arge and Ke Yi Department of Computer Science Duke University.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
COSC 6114 Prof. Andy Mirzaian. References: [M. de Berge et al] chapter 5 Applications: Data Base GIS, Graphics: crop-&-zoom, windowing.
1 Persistent data structures. 2 Ephemeral: A modification destroys the version which we modify. Persistent: Modifications are nondestructive. Each modification.
1 Finger search trees. 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2) : Assumes that.
External Memory Geometric Data Structures
AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
I/O-Algorithms Lars Arge University of Aarhus February 21, 2005.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
Special Cases of the Hidden Line Elimination Problem Computational Geometry, WS 2007/08 Lecture 16 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen,
1 Balanced Search Trees  several varieties  AVL trees  trees  Red-Black trees  B-Trees (used for searching secondary memory)  nodes are added.
I/O-Algorithms Lars Arge University of Aarhus February 13, 2005.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
Geometric Data Structures Computational Geometry, WS 2007/08 Lecture 13 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
I/O-Algorithms Lars Arge Aarhus University March 5, 2008.
I/O-Algorithms Lars Arge Aarhus University March 9, 2006.
1 Geometric index structures April 15, 2004 Based on GUW Chapter , [Arge01] Sections 1, 2.1 (persistent B- trees), 3-4 (static versions.
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
Fractional Cascading and Its Applications G. S. Lueker. A data structure for orthogonal range queries. In Proc. 19 th annu. IEEE Sympos. Found. Comput.
AALG, lecture 11, © Simonas Šaltenis, Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.
Orthogonal Range Searching I Range Trees. Range Searching S = set of geometric objects Q = query object Report/Count objects in S that intersect Q Query.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
UNC Chapel Hill M. C. Lin Orthogonal Range Searching Reading: Chapter 5 of the Textbook Driving Applications –Querying a Database Related Application –Crystal.
External Memory Algorithms for Geometric Problems Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)
14/13/15 CMPS 3130/6130 Computational Geometry Spring 2015 Windowing Carola Wenk CMPS 3130/6130 Computational Geometry.
Bin Yao Spring 2014 (Slides were made available by Feifei Li) Advanced Topics in Data Management.
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
Lars Arge Presented by Or Ozery. I/O Model Previously defined: N = # of elements in input M = # of elements that fit into memory B = # of elements per.
2IL50 Data Structures Fall 2015 Lecture 9: Range Searching.
Search Trees. Binary Search Tree (§10.1) A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying.
1 Trees 4: AVL Trees Section 4.4. Motivation When building a binary search tree, what type of trees would we like? Example: 3, 5, 8, 20, 18, 13, 22 2.
Interval S = [3,10]  {x | 3 ≤ x ≤ 10} Closed segment S = (3,10)  {x | 3 < x < 10} Opened segment S = [3,3]  {3} Point.
CMPS 3130/6130 Computational Geometry Spring 2015
AVL TREES By Asami Enomoto CS 146 AVL Tree is… named after Adelson-Velskii and Landis the first dynamically balanced trees to be propose Binary search.
February 17, 2005Lecture 6: Point Location Point Location (most slides by Sergi Elizalde and David Pritchard)
CS 6310 Advanced Data Structures Tree Structures for Set of Intervals by Halil Ibrahim DURSUNOGLU.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables II.
May 2012Range Search Algorithms1 Shmuel Wimer Bar Ilan Univ. Eng. Faculty Technion, EE Faculty.
3.1 Height-Balanced Trees 3.2 Weight-Balanced Trees
Computational Geometry
AA Trees.
Geometric Data Structures
Search Trees.
CMPS 3130/6130 Computational Geometry Spring 2017
Finger search trees.
Tree data structure.
Orthogonal Range Searching and Kd-Trees
Tree data structure.
Chapter 14: Augmenting Data Structures
Reporting (1-D) Given a set of points S on the line, preprocess them to build structure that allows efficient queries of the from: Given an interval I=[x1,x2]
Orthogonal Range Searching Querying a Database
2-3-4 Trees Red-Black Trees
Shmuel Wimer Bar Ilan Univ., School of Engineering
AVL Search Tree put(9)
CMSC 341 Splay Trees.
CMPS 3130/6130 Computational Geometry Spring 2017
Range Queries on Uncertain Data
Dynamic rectangular intersection with priorities
Weak Visibility Queries of Line Segments in Simple Polygons
CMSC 341 Splay Trees.
Dynamic rectangular intersection with priorities
Presentation transcript:

Segment tree and Interval Tree Segment Tree: Dutch book Interval Tree: CMPT 307 text (Notes of Hiam Kaplan of Tel Aviv U.)

The problem (1-D) Given a set of segments S on the line, preprocess them to build a structure that allows efficient queries of the from: Given a point x find all intervals containing it. x

Segment tree A B C D E F G H I J K A B C E J G I F K H D Place segment s in any node v such that s contains the segment corresponding to v but not the segment corresponding to p(v)

Segment tree (Cont) Keep a list of segments at each node A B C D E F G A B C D E F G H I J K A B C E J G I F K H D Keep a list of segments at each node

Segment tree (analysis) Each segment appears in at most 2 nodes per level.  Space O(n log n) To answer a query x, traverse the search path of x and report all segments in these nodes  O(log n + k) time

Segment tree -- query A B C D E F G H I J K x A B C E J G I F K H D

Dynamic segment trees A B C D E F G H I J K A B C E J G I F K H D

Dynamic segment trees A B D E F G H I J K C’ C’’ A B C E J G I F K H D

Dynamic segment trees A B C D E F G H I J K C’ C’’ A B D E C’ C’’ F G A B C D E F G H I J K C’ C’’ A B D E C’ C’’ F G H I J K

Dynamic segment trees A B C D E F G I J K H’ H’’ C’ C’’ A B D E C’ C’’ A B C D E F G I J K H’ H’’ C’ C’’ A B D E C’ C’’ F G H I J K

Dynamic segment trees A B C D E F G I J K H’ H’’ C’ C’’ A B D E C’ C’’ A B C D E F G I J K H’ H’’ C’ C’’ A B D E C’ C’’ F G I J K H’ H’’

Rotations…. What about rebalancing ? x y <===> a A y x C b B C A The number of intervals involved is proportional to the size of the subtree underneath x

Dynamic segment tree (Cont) We need a BB(α) tree So we get insertions and deletions in O(log n) amortized time.

Interval tree Place segment s in the LCA of its endpoints A B C D E F A B C D E F G H I J K A B C E J G I F K H D Place segment s in the LCA of its endpoints

Interval tree (Cont) In each node maintain the segments sorted by A B C D E F G H I J K In each node maintain the segments sorted by Right endpoint Left endpoint In two balanced search trees A B C D E F G H I J K

A B C D E F G H I J K A B C D E F G H I J K The space is O(n) !

To do a query at x, traverse the search path of x: B C D E F G H I J K To do a query at x, traverse the search path of x: At each node traverse the right tree if you go right and the left tree if you go left A B C D E F G H I J K

y B C When you go left, traverse the left tree until you hit the first interval that does not contain the query (similarly when you go right) Query time is O(log n + k)

Dynamic interval tree C’ C’’ H’ H’’ A B C D E F G H I J K A B C D E F

Dynamic interval tree C’ C’’ H’ H’’ A B D E F G I J K A B D E C’ C’’ F

Dynamic interval tree C’ C’’ H’ H’’ A B D E F G I J K A B D E C’ C’’ F

Dynamic interval tree C’ C’’ H’ H’’ A B D E F G I J K A B D E C’ C’’ F

Rotations…. What about rebalancing ? x y <===> A y x C B C A B The number of intervals involved is proportional to the size of the subtree underneath x

Dynamic interval tree (Cont) We need a BB(α) tree So we get insertions and deletions in O(log n) amortized time.

Two-dimensional Extension Consider a set of horizontal line segments in the plane. The query object is a vertical line segments.

Segment tree- treating the horizontal line segments as intervals on a line A B C D E F G H I J K x A B C E J G I F K H D

At each internal node u: We keep the intervals stored at u in sorted y-order. If the x-value of the query interval q=qx× [y1:y2] is contained in Int(u), we determine the intersecting intervals at u with query q in O(log nv+kv) time where nu is the number of intervals stored at u and ku is the number of intersecting intervals.

Total query time: There are O(logn) nodes. Total query time is O(log2n+k) time.