Augnenting data structures Augment an existing data structure to apply to a new problem. Red-black tree as an example.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

CSE 4101/5101 Prof. Andy Mirzaian Augmenting Data Structures.
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
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.
CS 332: Algorithms Binary Search Trees. Review: Dynamic Sets ● Next few lectures will focus on data structures rather than straight algorithms ● In particular,
Red-Black tree Recall binary search tree –Key values in the left subtree = the node value Operations:
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture six Dr. Hamdy M. Mousa.
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.
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.
David Luebke 1 5/22/2015 ITCS 6114 Universal Hashing Dynamic Order Statistics.
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.
Lecture 12: Balanced Binary Search Trees Shang-Hua Teng.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
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.
AVL Trees / Slide 1 Balanced Binary Search Tree  Worst case height of binary search tree: N-1  Insertion, deletion can be O(N) in the worst case  We.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 4 Image Slides.
David Luebke 1 7/2/2015 Medians and Order Statistics Structures for Dynamic Sets.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
Chapter 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
Red-Black Trees Lecture 10 Nawazish Naveed. Red-Black Trees (Intro) BSTs perform dynamic set operations such as SEARCH, INSERT, DELETE etc in O(h) time.
Data Structures - CSCI 102 Binary Tree In binary trees, each Node can point to two other Nodes and looks something like this: template class BTNode { public:
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.
Red-Black tree Recall binary search tree –Key values in the left subtree = the node value Operations:
October 19, 2005Copyright © by Erik D. Demaine and Charles E. LeisersonL7.1 Introduction to Algorithms 6.046J/18.401J LECTURE 10 Balanced Search.
Introduction to Algorithms Jiafen Liu Sept
Data Structures Balanced Trees 1CSCI Outline  Balanced Search Trees 2-3 Trees Trees Red-Black Trees 2CSCI 3110.
2IL50 Data Structures Fall 2015 Lecture 7: Binary Search Trees.
AVL Tree Definition: Theorem (Adel'son-Vel'skii and Landis 1962):
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 9.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 11 Prof. Erik Demaine.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
ECOE 556: Algorithms and Computational Complexity Heapsort Serdar Taşıran.
2IL05 Data Structures Spring 2010 Lecture 9: Augmenting Data Structures.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
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.
Dynamic Order Statistics
Augmenting Data Structures
Chapter 14: Augmenting Data Structures
CS 583 Analysis of Algorithms
Introduction to Algorithms
CSE2331/5331 Topic 7: Balanced search trees Rotate operation
Augmenting Data Structures: Interval Trees
Binary Search Trees Comp 122, Spring 2004.
Chapter 12&13: Binary Search Trees (BSTs)
Interval Trees CS302 Data Structures Modified from Dr Monica Nicolescu.
Presentation transcript:

Augnenting data structures Augment an existing data structure to apply to a new problem. Red-black tree as an example.

Dynamic order statistic (ith element) Chapter 9, O(n) algorithm Red-black tree gives a total order via inorder traversal, i.e., reflecting the rank of an element. –Two additional operations: Find ith smallest element. Find the rank of an element. How to modify it? Add a field, size in every node, i.e., size[x] is the size of the subtree rooted at x, including x. So assume sentinel’s size size[NIL]=0, then, size[x]=size[left[x]]+size[right[x]]+1. If so, easy to find the ith element, or the rank of an element in log(n) time. (page 304, 305). How to maintain size field during insertion or deletion?

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Loop invariant: at start of each iteration, r is the rank of key[x] in the subtree rooted at y.

Insertion operation Same two passes: –Insert x into tree, by going down, increase size by 1 for each node visited. –Modify the color and rotation by going up. Only the rotation will affect the size of some nodes, Fortunately, local modification. Same for deletion operation.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. How to modify the size field of left-rotation: size[y]=size[x], size[x]=size[left[x]]+size[left[y]]+1.

How to augment a data structure 1.Choosing an underlying DS 2.Determining additional information to be maintained in the underlying DS 3.Verifying that the additional information can be maintained for the basic modification operations on the underlying DS 4.Developing new operations

Augmenting a red-black tree Theorem 14.1 (page 309): –Let f be a field that augments a red-black tree T of n nodes, and suppose the f of a node x can be computed using only the information in node x, left[x], right[x], including f[left[x]] and f[right[x]]. Then we can maintain all values of f in all nodes during insertion and deletion without asymptotically affecting the O(log(n)).

Interval tree: dynamic set of intervals Intervals Closed intervals, open intervals, half- intervals. New operations: –INTERVAL-INSERT(T,x), x=[t1,t2]. –INTERVAL-DELETE(T,x), x=[t1,t2]. –INTERVAL-SEARCH(T,i), return a pointer x such that the interval of x overlaps with i.

How to implement? Select a underlying DS, red-back tree –The node x contains interval int[x], and the low[int[x]] is the node’s key. Additional information: max Maintain the information: –max[x]=max(high[int[x]],max[left[x]],max[right[ x]]). –By Theorem 14.1, can be done in log(n). Implementation of INTERVAL-SEARCH.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

If go to right, then safe since there is no interval in the left overlapping with i. If go to left, either there is an interval in the left overlapping with I or there is no overlaps. In the latter, we can prove that there will also be no overlaps in the right.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.