Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Chapter 12 Binary Search Trees
Jan Binary Search Trees What is a search binary tree? Inorder search of a binary search tree Find Min & Max Predecessor and successor BST insertion.
Analysis of Algorithms CS 477/677 Binary Search Trees Instructor: George Bebis (Appendix B5.2, Chapter 12)
Binary Search Trees Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
CS 332: Algorithms Binary Search Trees. Review: Dynamic Sets ● Next few lectures will focus on data structures rather than straight algorithms ● In particular,
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture six Dr. Hamdy M. Mousa.
The complexity and correctness of algorithms (with binary trees as an example)
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.
David Luebke 1 5/4/2015 Binary Search Trees. David Luebke 2 5/4/2015 Dynamic Sets ● Want a data structure for dynamic sets ■ Elements have a key and satellite.
Binary Search Trees Comp 550.
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.
Augnenting data structures Augment an existing data structure to apply to a new problem. Red-black tree as an example.
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.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 10.
2IL50 Data Structures Spring 2015 Lecture 8: Augmenting Data Structures.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 11.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 12.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 11.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Amortized Analysis Some of these lecture slides are adapted from CLRS.
Analysis of Algorithms CS 477/677 Red-Black Trees Instructor: George Bebis (Chapter 14)
10/22/2002CSE Red Black Trees CSE Algorithms Red-Black Trees Augmenting Search Trees Interval Trees.
1.1 Data Structure and Algorithm Lecture 12 Binary Search Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Binary Search Trees.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part II Prof. Dr. Th. Ottmann Summer Semester 2006.
David Luebke 1 7/2/2015 ITCS 6114 Binary Search Trees.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
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.
Design & Analysis of Algorithms Unit 2 ADVANCED DATA STRUCTURE.
Interval Trees.
David Luebke 1 9/18/2015 CS 332: Algorithms Red-Black Trees.
Lecture X Augmenting Data Structures
Introduction to Algorithms Jiafen Liu Sept
1 Red-Black Trees By Mary Hudachek-Buswell Red Black Tree Properties Rotate Red Black Trees Insertion Red Black Trees.
2IL50 Data Structures Fall 2015 Lecture 7: Binary Search Trees.
Binary SearchTrees [CLRS] – Chap 12. What is a binary tree ? A binary tree is a linked data structure in which each node is an object that contains following.
Binary Search Tree Qamar Abbas.
October 3, Algorithms and Data Structures Lecture VII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS 473Lecture X1 CS473-Algorithms Lecture RED-BLACK TREES (RBT)
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.
1 Algorithms CSCI 235, Fall 2015 Lecture 22 Binary Search Trees.
Binary Search Trees Lecture 6 Asst. Prof. Dr. İlker Kocabaş 1.
Red-Black Trees. Review: Binary Search Trees ● Binary Search Trees (BSTs) are an important data structure for dynamic sets ● In addition to satellite.
October 19, 2005Copyright © by Erik D. Demaine and Charles E. LeisersonL7.1 Introduction to Algorithms LECTURE 8 Balanced Search Trees ‧ Binary.
Lecture 19. Binary Search Tree 1. Recap Tree is a non linear data structure to present data in hierarchical form. It is also called acyclic data structure.
Mudasser Naseer 1 1/25/2016 CS 332: Algorithms Lecture # 10 Medians and Order Statistics Structures for Dynamic Sets.
Analysis of Algorithms CS 477/677 Red-Black Trees Instructor: George Bebis (Chapter 14)
2IL05 Data Structures Spring 2010 Lecture 9: Augmenting Data Structures.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 10.
Binary Search Trees What is a binary search tree?
Analysis of Algorithms CS 477/677
Introduction to Algorithms
CS200: Algorithms Analysis
CS 583 Analysis of Algorithms
Augmenting Data Structures
Chapter 14: Augmenting Data Structures
Binary Search Trees (13.1/12.1)
Chapter 12: Binary Search Trees
CS 583 Analysis of Algorithms
Introduction to Algorithms
Analysis of Algorithms CS 477/677
Design and Analysis of Algorithms
Augmenting Data Structures: Interval Trees
Analysis of Algorithms CS 477/677
Binary Search Trees Comp 122, Spring 2004.
Chapter 12&13: Binary Search Trees (BSTs)
Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu.
Red-Black Trees CS302 Data Structures
Presentation transcript:

Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu

2 Interval Trees Useful for representing a set of intervals –E.g.: time intervals of various events Each interval i has a low[i] and a high[i] –Assume close intervals

Interval Properties Intervals i and j overlap iff: low[i] ≤ high[j] and low[j] ≤ high[i] Intervals i and j do not overlap iff: high[i] < low[j] or high[j] < low[i] i j i j i j i j ij ji 3

Interval Trichotomy Any two intervals i and j satisfy the interval trichotomy: –exactly one of the following three properties holds: a)i and j overlap low[i] ≤ high[j] and low[j] ≤ high[i] b)i is to the left of j high[i] < low[j] c)i is to the right of j high[j] < low[i] 4

Interval Trees Def.: Interval tree = a red-black tree that maintains a dynamic set of elements, each element x having associated an interval int[x]. Operations on interval trees: –INTERVAL-INSERT( T, x ) –INTERVAL-DELETE( T, x ) –INTERVAL-SEARCH( T, i ) 5

Designing Interval Trees 1.Underlying data structure –Red-black trees –Each node x contains: an interval int[x], and the key: low[int[x]] –An inorder tree walk will list intervals sorted by their low endpoint 2.Additional information –max[x] = maximum endpoint value in subtree rooted at x 3.Maintaining the information max[x] = Constant work at each node, so still O(lgn) time high[int[x]] max max[left[x]] max[right[x]] [16, 21] 30 [25, 30] 30 [26, 26] 26 [17, 19] 20 [19, 20] 20 [8, 9] 23 [15, 23] 23 [5, 8] 10 [6, 10] 10 [0, 3] 3 high low

Designing Interval Trees 4.Develop new operations INTERVAL-SEARCH( T, i ): –Returns a pointer to an element x in the interval tree T, such that int[x] overlaps with i, or NIL otherwise Idea: Check if int[x] overlaps with i –Max[left[x]] ≥ low[i] Go left –Otherwise, go right [16, 21] 30 [25, 30] 30 [26, 26] 26 [17, 19] 20 [19, 20] 20 [8, 9] 23 [15, 23] 23 [5, 8] 10 [6, 10] 10 [0, 3] 3 high low

INTERVAL-SEARCH( T, i ) 1.x ← root[T] 2.while x  nil and i does not overlap int[x] 3. do if left[x]  nil and max[left[x]] ≥ low[i] 4. then x ← left[x] 5. else x ← right[x] 6.return x 8

Example [16, 21] 30 [25, 30] 30 [26, 26] 26 [17, 19] 20 [19, 20] 20 [8, 9] 23 [15, 23] 23 [5, 8] 10 [6, 10] 10 [0, 3] 3 i = [11, 14] x x x x = NIL i = [22, 25] 9

Theorem At the execution of interval search: if the search goes right, then either: –There is an overlap in right subtree, or –There is no overlap in either subtree Similar when the search goes left It is safe to always proceed in only one direction 10

Theorem Proof: If search goes right: –If there is an overlap in right subtree, done –If there is no overlap in right  show there is no overlap in left –Went right because: left[x] = nil[T]  no overlap in left, or m ax[left[x]] < low[i]  no overlap in left i max[left[x]]low[x] 11

Theorem - Proof If search goes left: If there is an overlap in left subtree, done If there is no overlap in left  show there is no overlap in right Went left because: low[i] ≤ max[left[x]] = high[j] for some j in left subtree int[root] max [low[j], high[j]] max[j] [low[k], high[k]] max[k] high[j] < low[i] high[i] < low[j] iij low[j] < low[k] k high[i] < low[k] max[left] 12 No overlap!