CS 310 Unit 14 Augmenting Data Structures

CS 310 Unit 14 Augmenting Data Structures - CS 310 Unit 14...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 310 Unit 14 Augmenting Data  Structures Furman Haddix Ph.D. Assistant Professor Minnesota State University,  Mankato Spring 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
Exam 2 Exam on Monday, March 31 Review on Thursday, March 27 Covers Chapters 9-14
Background image of page 2
Augmenting Data Structures  Objectives  Why augment data structures? Example Augmenting red-black trees Dynamic order statistics A methodology for augmenting data structures Example Augmenting red-black trees Interval trees Text, Chapter 14
Background image of page 3

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

View Full DocumentRight Arrow Icon
Why Augment Data Structures? Rarely will you be asked to “program up” a red-black  tree. More likely you will be asked to provide a solution to a  particular problem In a dynamic environment maintain a database such  that decile and quartile information can be extracted. You should be able to recognize that this is an  dynamic order statistics problem Next, you need to decide upon a means of effectively  implementing your solution This often means augmenting an existing data structure  and supporting algorithms to provide a solution that is  both specific to the problem but maintains most  characteristics of the existing data structure and 
Background image of page 4
Example: Augmenting Red-black  Trees to Implement Dynamic Order  Statistics Idea:  Augment red-black tree to provide dynamic order  statistics by keeping subtree size.  This will allow O(lg n) insertion, deletion, and order  statistic retrieval. Augment algorithms to maintain size: Size of subtree rooted at x: x->size() = x->left()->size() + x->right()->size() + 1 Additional operations required: s = size(x): returns size of subtree rooted at x (including x) y = select(i, x): returns pointer to ith smallest key of subtree  rooted at x. i = rank(x): returns the rank of x in tree.
Background image of page 5

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

View Full DocumentRight Arrow Icon
size(x) int size(Node *x) { // returns size of subtree rooted at x // (including x) if (x == null) return 0; int i = 1; if(x->left() != null) i += x->left()->size(); if(x->right() != null) i += x->right()->size(); return i; } // Note that size() is overloaded // to compute size(x) based on // children, or simply return size // variable of local node (size()) Node *p; Node *left; Node *right; type key;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

CS 310 Unit 14 Augmenting Data Structures - CS 310 Unit 14...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online