Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part II Prof. Dr. Th. Ottmann Summer Semester 2006.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

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.
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.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture six Dr. Hamdy M. Mousa.
Binary Search Trees. A binary search tree is a binary tree that keeps the following property: Every element is larger than all elements in its left sub-tree.
CS 473Lecture X1 CS473-Algorithms I Lecture X Augmenting Data Structures.
David Luebke 1 5/22/2015 CS 332: Algorithms Augmenting Data Structures: Interval Trees.
14. Augmenting Data Structures Hsu, Lih-Hsing. Computer Theory Lab. Chapter 13P Dynamic order statistics We shall also see the rank of an element―its.
2IL50 Data Structures Spring 2015 Lecture 8: Augmenting Data Structures.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 11.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 12.
AVL-Trees (Part 1) COMP171. AVL Trees / Slide 2 * Data, a set of elements * Data structure, a structured set of elements, linear, tree, graph, … * Linear:
IP-Lookup and Packet Classification, II Advanced Algorithms & Data Structures Lecture Theme 8 Prof. Dr. Th. Ottmann Summer Semester 2006.
Orthogonal Range Searching-1Computational Geometry Prof. Dr. Th. Ottmann 1 Orthogonal Range Searching 1.Linear Range Search : 1-dim Range Trees 2.2-dimensional.
AVL-Trees (Part 1: Single Rotations) Lecture COMP171 Fall 2006.
1 Theory I Algorithm Design and Analysis (3 - Balanced trees, AVL trees) Prof. Th. Ottmann.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
10/22/2002CSE Red Black Trees CSE Algorithms Red-Black Trees Augmenting Search Trees Interval Trees.
1 Geometric Solutions for the IP-Lookup and Packet Classification Problem (Lecture 12: The IP-LookUp & Packet Classification Problem, Part II) Advanced.
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.
Point Location Computational Geometry, WS 2007/08 Lecture 5 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 - Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
Introduction to Analysis of Algorithms CAS CS 330 Lecture 16 Shang-Hua Teng Thanks to Charles E. Leiserson and Silvio Micali of MIT for these slides.
Balanced Search Trees CS 3110 Fall Some Search Structures Sorted Arrays –Advantages Search in O(log n) time (binary search) –Disadvantages Need.
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.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Interval Trees.
Lecture X Augmenting Data Structures
Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu.
14/13/15 CMPS 3130/6130 Computational Geometry Spring 2015 Windowing Carola Wenk CMPS 3130/6130 Computational Geometry.
2IL50 Data Structures Fall 2015 Lecture 7: Binary Search Trees.
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.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 9.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 11 Prof. Erik Demaine.
SEGMENT TREES. Originally introduced by Bentley(1977) Handle intervals on the real line whose end-points belong to a fixed set of N abscissae. A static.
AVL trees1 AVL Trees Height of a node : The height of a leaf is 1. The height of a null pointer is zero. The height of an internal node is the maximum.
CMPS 3130/6130 Computational Geometry Spring 2015
2IL05 Data Structures Spring 2010 Lecture 9: Augmenting Data Structures.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 10.
Analysis of Algorithms CS 477/677
Lec 13 Oct 17, 2011 AVL tree – height-balanced tree Other options:
Introduction to Algorithms
BCA-II Data Structure Using C
CMPS 3130/6130 Computational Geometry Spring 2017
Balancing Binary Search Trees
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Chapter 14: Augmenting Data Structures
Binary Search Trees (13.1/12.1)
Introduction to Algorithms
Topic 6: Binary Search Tree Data structure Operations
AVL-Trees (Part 1).
Binary SearchTrees [CLRS] – Chap 12.
Lecture 10 Oct 1, 2012 Complete BST deletion Height-balanced BST
Design and Analysis of Algorithms
Augmenting Data Structures: Interval Trees
Chapter 12&13: Binary Search Trees (BSTs)
Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu.
Presentation transcript:

Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part II Prof. Dr. Th. Ottmann Summer Semester 2006

2 Examples for Augmenting DS Dynamic order statistics: Augmenting binary search trees by size information D-dimensional range trees: Recursive construction of (static) d-dim range trees Min-augmented dynamic range trees: Augmenting 1-dim range trees by min- information Interval trees Priority search trees

3 Interval Trees (CLR-Version) Problem: Given a set R of intervals that changes under insertions and deletions, construct a data structure to store R that can be updated in O(log n) time and that can find for any given query interval i an interval in R that overlaps i, and returns nil if there is no such interval, in O(log n) time. Idea: Store the set of intervals in an appropriately augmented balanced binary search tree and design an algorithm for the new operation. Interval-search(T, i): Report an interval stored in T that overlaps the query interval i, if such an interval exists, and Nil otherwise.

4 Observation Let i = [low(i), high(i)] and i‘ = [low(i‘), high(i‘)] be two intervals. Then i and i‘ overlap if and only if low(i) ≤ high(i‘) and low(i‘) ≤ high(i) Any two intervals satisfy the interval trichotomy: a)i and i‘ overlap b)high(i) ≤ low(i‘) c)high(i‘) ≤ low(i)

5 Interval Trichotomy The cases when intervals I 1 and I 2 overlap: The cases when intervals I 1 and I 2 do not overlap: x1x1 y1y1 x2x2 y2y2 x1x1 y1y1 x2x2 y2y2 x1x1 y1y1 x2x2 y2y2 x1x1 y1y1 x2x2 y2y2 x2x2 y2y2 x1x1 y1y1 x1x1 y1y1 x2x2 y2y2

6 Interval tree (CLR Version) [0,3] [6,10] [8,9] [15,23] [16,21] [17,19] [25,30] [27,33] [26,26] [5,8] [29,30] [19,20] 20 Each node v stores an interval int(v) and the maximum upper endponit of all intervals stored in the subtree rooted at v; The interval tree is a search tree on the lower endpoints of intervals. Max(v) is the maximum value of all right endpoints in the subtree rooted at v.

7 Maintaining max-information Max (x) = max(high(int(x), max (left(x)), max (right(x)) Max-information can be maintained during updates and rebalancing operations (rotations).

8 Finding an interval in T that overlaps interval i [0,3] [6,10] [8,9] [15,23] [16,21] [17,19] [25,30] [27,33] [26,26] [5,8] [29,30] [19,20] 20 Interval-search(T, i) x  root(T) while x ≠ Nil and i does not overlap int(x) do if left(x) ≠ Nil and max(left(x))≥ low(i) then x  left(x) else x  right(x) return x Interval-search can be carried out in time O(height T). Observation: if int(x) does not overlap i, the search always proceeds in a safe direction!

9 Interval Trees: Point-set Variant Problem: Given a set R of intervals that changes under insertions and deletions, construct a data structure to store R that can be updated in O(log n) time and that can find for any given query interval i an interval in R that overlaps i, and returns nil if there is no such interval, in O(log n) time. Solution: Map intervals to points and store points in appropriately augmented tree. i l = low[i]r = high[i] (l, r)

10 Max-augmented Range Tree (2, 5)(3, 4)(4, 5) (8, 13)(10, 15) (11, 12) (14, 17) (21, 28)(15, 22)(17, 18) Store intervals as points in sorted x-order in a leaf search tree. Store max y-coordinates at internal nodes. Leaf-search tree on x-coordinates of points Max-tournament tree on y-coordinates of points 2822

11 Interval Search Interval-Search(T, i) /* Find an interval in tree T that overlaps i */ 1 P = root[T] 2while p is not a leaf do 3 if max-y[left[p]]  low[i] 4then p = left[p] 5else p = right[p] /* Now p is a leaf storing interval i’ */ 6If (i and i’ overlap) then return “found” else return “not found”

12 Correctness Proof Case 1: We go right, low[i] > max-y[left[p]] i Intervals in left subtree of p None of them can overlap with i.

13 Correctness Proof Case 2: We go left, low[i] ≤ max-y[left[p]] If T[left[p]] does not contain an interval i‘ that overlaps i, then T[right[p]] cannot contain such an interval as well! i i‘ max-y[left[p]] (Here we utilize the fact that the intervals are sorted according to their x-coordinates!)

14 Interval Tree-Summary A interval tree for a set of n intervals [l 1, r 1 ], …, [l n, r n ] on the line is a daynamic max- augmented range tree for the set of points P = {(l 1, r 1 ), …, (l n, r n )}. Interval trees can be used to carry out the following operations: Interval-Insert(T, i) inserts the interval i into the tree T Interval-Delete(T, i) removes the interval i from the tree T Interval-Search(T, i) returns a pointer to a node storing an interval i‘ that overlaps i, or NIL if no such interval is stored in T.

15 Examples for Augmenting DS Dynamic order statistics: Augmenting binary search trees by size information D-dimensional range trees: Recursive construction of (static) d-dim range trees Min-augmented dynamic range trees: Augmenting 1-dim range trees by min- information Interval trees Priority search trees

16 3-Sided Range Queries Goal: Report all k points in the query range in O(log n + k) time.

17 3-Sided Range Queries Goal: Report all k points in the query range in O(log n + k) time. Age Salary

18 Priority Search Trees Two data structures in one: ● Search tree on points’ x-coordinates ● Heap on points’ y-coordinates { (2, 12), (3, 4) (4, 11), (5, 3), (8, 5), (11, 21), (14, 7), (15, 2), (17, 30), (21, 8), (33, 33) }

19 Priority Search Trees (33, 33) (17, 30) (21, 8) (15, 2) (11, 21) (2, 12)(4, 11) (5, 3) Two data structures in one: ● Search tree on points’ x-coordinates ● Heap on points’ y-coordinates (8, 5) (14, 7) (3, 4)

20 Query procedure: Inspect all nodes on the two bounding paths and report the points that match the query. For every tree between the two bounding paths, apply the following strategy: Inspect the root. If this reports a point, recursively visit the children of the root. 3-Sided Range Queries on a Priority Search Tree O(log n) time to query red paths O(log n + k) time to query blue subtrees

21 Observations: We never report a point that is not in the query range. Points in the yellow subtrees cannot match the query. Points in the blue subtrees that are not reported cannot match the query. Correctness of the Query Procedure

22 Insertion into a Priority Search Tree Insertion procedure: 1. Insert new leaf based on point’s x-coordinate. 2. Insert point down the tree, based on its y-coordinate (33, 33) (17, 30) (21, 8) (15, 2) (11, 21) (2, 12)(4, 11) (5, 3) (8, 5) (14, 7) (3, 4)

23 Deletion from a Priority Search Tree Deletion procedure: 1. Search for the point and delete it. 2. Fill the gap by pulling-up points according to their y-values (33, 33) (17, 30) (21, 8) (15, 2) (11, 21) (2, 12)(4, 11) (5, 3) (8, 5) (14, 7) (3, 4)

24 Priority Search Tress: Observations Insertion and deletion of point in a priority search tree T of n nodes can be carried out in time O(height(T)). Priority search trees support north-grounded range reporting, if the heap-structure is a max-heap, and they support south-grounded range reporting, if the heap-structure is a min-heap. Maintaining the height of the leaf search tree underlying a priority search tree such that the height is always of order O(log n) for a priority search tree storing n nodes requires rebalancing! In order to obtain O(log n) algorithms for insertion and deletion of points one must use a rebalancing scheme with constant restructuring cost per update! A PST storing n points requires space O(N).

25 Rotations in a Priority Search Tree p1p1 p2p2 p1p1 ? Push p 2 to the appropriate child of y. Store p 1 at y. Propagate the point with maximal y-coordinate from the appropriate child of x. x y y x

26 Priority Search Trees — Summary Theorem: There exists a data structure to represent a dynamically changing set S of points in two dimensions with the following properties: The data structure can be updated in O(log n) time after every insertion or deletion into or from S. The data structure allows us to answer 3-sided range queries in O(log n + k) time. The data structure occupies O(n) space.