14. Augmenting Data Structures Hsu, Lih-Hsing. Computer Theory Lab. Chapter 13P.2 14.1 Dynamic order statistics We shall also see the rank of an element―its.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

CSE 4101/5101 Prof. Andy Mirzaian Augmenting Data Structures.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
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.
Binary Search Trees Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Introduction to Algorithms Jiafen Liu Sept
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.
Chapter 12 Binary search trees Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from.
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.
CSE 2331/5331 Topic 10: Balanced search trees Rotate operation Red-black tree Augmenting data struct.
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.
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.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE Binary search trees Motivation Operations on binary search trees: –Search –Minimum,
13. Red-Black Tree Hsu, Lih-Hsing. Computer Theory Lab. Chapter 13P.2 One of many search-tree schemes that are “ balanced ” in order to guarantee that.
David Luebke 1 7/2/2015 ITCS 6114 Binary Search Trees.
DAST 2005 Tirgul 7 Binary Search Trees. DAST 2005 Motivation We would like to have a dynamic ADT that efficiently supports the following common operations:
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.
12.Binary Search Trees Hsu, Lih-Hsing. Computer Theory Lab. Chapter 12P What is a binary search tree? Binary-search property: Let x be a node in.
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
© 2014 by Ali Al Najjar Introduction to Algorithms Introduction to Algorithms Red Black Tree Dr. Ali Al Najjar Day 18 L10.1.
Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu.
Mudasser Naseer 1 10/20/2015 CSC 201: Design and Analysis of Algorithms Lecture # 11 Red-Black Trees.
Chapter 13 Red-Black Trees Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from the.
2IL50 Data Structures Fall 2015 Lecture 7: Binary Search Trees.
2IL50 Data Structures Fall 2015 Lecture 9: Range Searching.
October 3, Algorithms and Data Structures Lecture VII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
Red Black Tree Essentials Notes from “Introduction to Algorithms”, Cormen et al.
Red-Black Trees. Review: Binary Search Trees ● Binary Search Trees (BSTs) are an important data structure for dynamic sets ● In addition to satellite.
Lecture 91 Data Structures, Algorithms & Complexity Insertion and Deletion in BST GRIFFITH COLLEGE DUBLIN.
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
CS 332: Algorithms Red-Black Trees David Luebke /20/2018.
Augmenting Data Structures
Chapter 14: Augmenting Data Structures
Binary Search Trees (13.1/12.1)
Algorithms and Data Structures Lecture VII
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:

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 position in the linear order of the set―can likewise be determined in O(lg n) time.

Computer Theory Lab. Chapter 13P.3 Beside the usual red-black tree fields key[x], color[x], p[x], left[x], and right[x] in a node x, we have another field size[x]. This field contains the number of ( internal ) nodes in the subtree rooted at x (including x itself), that is the size of the subtree. If we define the sentinel ’ s size to be 0, that is, we set size[nil[T]] to be 0, then we have the identity size[x] = size[left[x]] + size[right[x]] +1

Computer Theory Lab. Chapter 13P.4 An order-statistic tree

Computer Theory Lab. Chapter 13P.5 Retrieving an element with a given rank OS-S ELECT (x, i) 1 r ← size[left[x] 2if i = r 3 then return x 4else if i < r 5 then return OS-S ELECT (left[x], i) 6else return OS-S ELECT (right[x], i – r) Time complexity :O(lg n)

Computer Theory Lab. Chapter 13P.6 Determining the rank of an element OS-R ANK (T, x) 1r ← size[left[x]] + 1 2y ← x 3while y ≠ root[T] 4 do if y = right[p[y]] 5then r ← r + size[left[p[y]]] y ← p[y] 7return r The running time of OS-RANK is at worst proportional to the height of the tree: O(lg n)

Computer Theory Lab. Chapter 13P.7 Maintaining subtree sizes Referring to the code for L EFT -R OTATE (T, x) in section 13.2 we add the following lines: 12 size[y] ← size[x] 13 size[x] ← size[left[x]] + size[right[x]] + 1

Computer Theory Lab. Chapter 13P.8 Updating subtree sizes during rotations

Computer Theory Lab. Chapter 13P How to augment a data structure 1.Choosing an underlying data structure, 2.Determining additional information to be maintained in the underlying data structure, 3.Verifying that the additional information can be maintained for the basic modifying operations on the underlying data structure, and 4.Developing new operations.

Computer Theory Lab. Chapter 13P.10 Augmenting red-black trees Theorem 14.1 (Augmenting a red-black tree) Let f be a field that augments a red-black tree T of n nodes, and suppose that the contents of f for a node x can be computed using only the information in nodes x, left[x], and right[x], including f[left[x]] and f[right[x]]. Then, we can maintain the values of f in all nodes of T during insertion and deletion without asymptotically affecting the O(lg n) performance of these operations.

Computer Theory Lab. Chapter 13P.11 Proof. The main idea of the proof is that a change to an f field in a node x propagates only to ancestors of x in the tree.

Computer Theory Lab. Chapter 13P Interval trees We can represent an interval[ t 1, t 2 ] as an object i, with fields low[i] = t 1 (the low endpoint) and high[i] = t 2 (the high endpoint). We say that intervals i and i’ overlap if i  i’ ≠ Ø, that is, if low[i] ≤ high[i’] and low[i’] ≤ high[i]. Any two intervals i and i’ satisfy the interval trichotomy; that exactly one of the following three properties holds: a. i and i’ overlap, b. i is to the left of i’ (i.e., high[i] < low[i’] ), c. i is to the right of i’ (i.e., high[i’] < low[i ])

Computer Theory Lab. Chapter 13P.13 The interval trichotomy for two colsed intervals i and i ’

Computer Theory Lab. Chapter 13P.14 An interval tree is a red-black tree that maintains a dynamic set of elements, with each element x containing an interval int[x].

Computer Theory Lab. Chapter 13P.15 Operations Interval trees support the following operations. I NTERVAL -I NSERT (T,x) I NTERVAL -D ELETE (T,x) I NTERVAL -S EARCH (T,i)

Computer Theory Lab. Chapter 13P.16 An interval tree

Computer Theory Lab. Chapter 13P.17

Computer Theory Lab. Chapter 13P.18 Design of an interval tree Step 1: underlying data structure Red-black tree Step 2: Additional information Each node x contains a value max[x], which is the maximum value of any interval endpoint stored in the subtree rooted at x. Step 3: Maintaining the information We determine max[x] given interval int[x] and the max values of node x’ s children: max[x] = max(high[int[x]], max[left[x]], max[right[x]]). Thus, by Theorem 14.1, insertion and deletion run in O(lg n) time.

Computer Theory Lab. Chapter 13P.19 Step 4: Develop new operations The only new operation we need is I NTERVAL - S EARCH (T, i ), which finds a node in tree T whose interval overlaps interval i. If there is no interval that overlaps i in the tree, a pointer to the sentinel nil[T] is returned.

Computer Theory Lab. Chapter 13P.20 INTERVAL-SEARCH(T, i) 1x ← root [T] 2while x ≠ nil[T] and i does not overlap int[x] 3 do if left[x] ≠ nil[T] and max[left[x]]  low[i] 4then x ← left[x] 5else x ← right[x] 6return x

Computer Theory Lab. Chapter 13P.21 Theorem 14.2 Any execution of I NTERVAL -S EARCH (T,i) either returns a node whose interval overlaps i, or it returns nil[T] and the tree T contain node whose interval overlaps i.