# Augment - CSE 4101/5101 Prof. Andy Mirzaian Augmenting Data...

This preview shows pages 1–9. Sign up to view the full content.

CSE 4101/5101 Augmenting Data Structures Prof. Andy Mirzaian

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
TOPICS Ø Augmentation Ø Order Statistics Dictionary Ø Interval Tree Ø Overlapping Windows 2
References: [CLRS] chapter 14 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Augmenting a Data Structure § Suppose we have a base data structure D that efficiently handles a standard set of operations. For instance, D is a Red-Black Tree that supports operations SEARCH, INSERT, and DELETE. § In some applications, besides the existing operations, we wish our data structure to support an additional set of operations. For instance, the order-statistics operations SELECT and RANK (see next slides). § How do we efficiently implement the new operations without degrading the efficiency of the existing ones? § This can be done by augmenting the data structure, i.e., maintaining added pieces of information in it to assist fast implementation of the new operations. § However, this forces revision of the existing operations to consistently maintain the augmented info while they modify D. § Given a new application, we need to figure out the following: 1. What is the base data structure D we wish to use? 2. What is the augmented information? 3. How do we efficiently implement the new ops on the augmented D? 4. How do we revise the existing operations on the augmented D, (ideally) without performance degradation? 4
ORDER STATISTICS Dictionary 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ORDER STATISTICS DICTIONARY Two new (inverse) operations: RANK(K,D): return the number of items in data set D that are  key K. SELECT(r,D): return the item in D with rank r (return nil if none exists). Solution 1: D as an un-ordered set of n items. RANK and SELECT can be done in O(n) time in the worst-case. RANK(K,D): Sequentially scan through D and count # items  K. SELECT(r,D): See [CLRS chapter 9] or my CSE3101 LS5 or LN4. Solution 2: D as a sorted array of n items. RANK takes O(log n) time by binary-search. SELECT takes O(1) time by probing rank index position. What about the dictionary operations? Solution 3: Augment a search tree. See next slides. 6
Augmenting a BST Let T be any BST. What is rank of the root? 1 + # items in the left subtree. L R root T: 1 2 1 1 1 3 5 3 9 Rank of root = 1 + size[left[root]]. Augmented info in each node x: size[x] = # items in the subtree rooted at x. (size[nil] = 0.) 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
SELECT on BST Rank(K,x) (* return rank of key K in BST rooted at x *) if x = nil then return 0 R  1+ size[left[x]] (* root rank *) if K = key[x] then return R if K < key[x] then return Rank(K,left[x]) if K > key[x] then return R + Rank(K, right[x]) end Select(r,x) (* return item of rank r in BST rooted at x *) if x = nil then return nil R  1+ size[left[x]] (* root rank *) if r = R then return x if r < R then return Select(r,left[x]) if r > R then return Select(r-R, right[x]) end Running time = O(# nodes on the search path). x
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/13/2012 for the course CSE 4101 taught by Professor Mirzaian during the Winter '12 term at York University.

### Page1 / 31

Augment - CSE 4101/5101 Prof. Andy Mirzaian Augmenting Data...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online