Lec11 - Introduction to Algorithms 6.046J/18.401J LECTURE 11 Augmenting Data Structures Dynamic order statistics Methodology Interval trees Prof

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

View Full Document Right Arrow Icon
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.1 Introduction to Algorithms 6.046J/18.401J L ECTURE 11 Augmenting Data Structures Dynamic order statistics Methodology Interval trees Prof. Charles E. Leiserson
Background image of page 1

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

View Full DocumentRight Arrow Icon
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.2 Dynamic order statistics OS-S ELECT ( i , S ) : returns the i th smallest element in the dynamic set S . OS-R ANK ( x , S ) : returns the rank of x S in the sorted order of S ’s elements. I DEA : Use a red-black tree for the set S , but keep subtree sizes in the nodes. key size key size Notation for nodes:
Background image of page 2
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.3 Example of an OS-tree M 9 M 9 C 5 C 5 A 1 A 1 F 3 F 3 N 1 N 1 Q 1 Q 1 P 3 P 3 H 1 H 1 D 1 D 1 size [ x ] = size [ left [ x ]] + size [ right [ x ]] + 1
Background image of page 3

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

View Full DocumentRight Arrow Icon
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.4 Selection Implementation trick: Use a sentinel (dummy record) for NIL such that size [ NIL ] = 0 . OS-S ELECT ( x , i ) i th smallest element in the subtree rooted at x k size [ left [ x ]] + 1 k = rank( x ) if i = k then return x if i < k then return OS-S ELECT ( left [ x ] , i ) else return OS-S ELECT ( right [ x ] , i – k ) (OS-R ANK is in the textbook.)
Background image of page 4
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.5 Example OS-S ELECT ( root , 5) M 9 M 9 C 5 C 5 A 1 A 1 F 3 F 3 N 1 N 1 Q 1 Q 1 P 3 P 3 H 1 H 1 D 1 D 1 i = 5 k = 6 M 9 M i = 5 k = 2 i = 3 k = 2 i = 1 k = 1 Running time = O ( h ) = O (lg n ) for red-black trees.
Background image of page 5

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

View Full DocumentRight Arrow Icon
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.6 Data structure maintenance Q. Why not keep the ranks themselves in the nodes instead of subtree sizes? A. They are hard to maintain when the red-black tree is modified. Modifying operations: I NSERT and D ELETE . Strategy: Update subtree sizes when inserting or deleting.
Background image of page 6
October 24, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L11.7 Example of insertion M 9 M 9 C 5 C 5 A 1 A 1 F 3 F 3 N 1 N 1 Q 1 Q 1 P 3 P 3 H 1 H 1 D 1 D 1 I NSERT (“K”) 10 10 6 6 4 4 2 2 K 1 K 1
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2010 for the course CS 477 taught by Professor Gewali during the Spring '08 term at University of Nevada, Las Vegas.

Page1 / 25

Lec11 - Introduction to Algorithms 6.046J/18.401J LECTURE 11 Augmenting Data Structures Dynamic order statistics Methodology Interval trees Prof

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

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