{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_10

# lecture_10 - Introduction to Algorithms...

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

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 10 Prof. Piotr Indyk

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

View Full Document
Introduction to Algorithms October 18, 2004 L10.2 © 2004 by Erik Demaine and Piotr Indyk Today A data structure for a new problem Amortized analysis
Introduction to Algorithms October 18, 2004 L10.3 © 2004 by Erik Demaine and Piotr Indyk 2-3 Trees: Deletions Problem: there is an internal node that has only 1 child Solution: delete recursively 9 12 5 1 6 7 5.5 12 5.5 6 6 12 12

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

View Full Document
Introduction to Algorithms October 18, 2004 L10.4 © 2004 by Erik Demaine and Piotr Indyk Example 9 12 5 1 6 7 8 5.5 8 12 5.5 6 6 12 12
Introduction to Algorithms October 18, 2004 L10.5 © 2004 by Erik Demaine and Piotr Indyk Example, ctd. 9 12 5 1 6 7 5.5 8 12 5.5 6 6 12 12

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

View Full Document
Introduction to Algorithms October 18, 2004 L10.6 © 2004 by Erik Demaine and Piotr Indyk Example, ctd. 9 12 5 1 6 7 5.5 12 5.5 12 6 12 12
Introduction to Algorithms October 18, 2004 L10.7 © 2004 by Erik Demaine and Piotr Indyk Example, ctd. 9 12 5 1 6 7 5.5 12 5.5 12 6

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

View Full Document
Introduction to Algorithms October 18, 2004 L10.8 © 2004 by Erik Demaine and Piotr Indyk Procedure for Delete(x) Let y=p(x) Remove x If y root then Let z be the sibling of y . Assume z is the right sibling of y , otherwise the code is symmetric. If y has only 1 child w left Case 1: z has 3 children Attach left[z] as the rightmost child of y Update y.max and z.max Case 2: z has 2 children: Attach the child w of y as the leftmost child of z Update z.max Delete( y ) (recursively * ) Else Update max of y , p(y) , p(p(y)) and so on until root Else If root has only one child u Remove root Make u the new root * Note that the input of Delete does not have to be a leaf x z y
Introduction to Algorithms October 18, 2004 L10.9 © 2004 by Erik Demaine and Piotr Indyk 2-3 Trees The simplest balanced trees on the planet! (but, nevertheless, not completely trivial)

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

View Full Document
Introduction to Algorithms October 18, 2004 L10.10 © 2004 by Erik Demaine and Piotr Indyk Dynamic Maintenance of Sets Assume, we have a collection of elements The elements are clustered Initially, each element forms its own cluster/set We want to enable two operations: – FIND-SET ( x ) : report the cluster containing x – UNION (C 1 , C 2 ) : merges the clusters C 1 , C 2 1 2 3 5 6
Introduction to Algorithms October 18, 2004 L10.11 © 2004 by Erik Demaine and Piotr Indyk Disjoint-set data structure (Union-Find) Problem: Maintain a collection of pairwise-disjoint sets S = { S 1 , S 2 , …, S r } . Each S i has one representative element x=rep [ S i ] . Must support three operations: M AKE -S ET ( x ) : adds new set { x } to S with rep [{ x }] = x (for any x S i for all i ). U NION ( x , y ) : replaces sets S x , S y with S x S y in S for any x , y in distinct sets S x , S y . F IND -S ET ( x ) : returns representative rep [ S x ] of set S x containing element x . rep. WEAK

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

View Full Document
Introduction to Algorithms October 18, 2004 L10.12 © 2004 by Erik Demaine and Piotr Indyk Quiz If we have a W EAK U NION ( x , y ) that works only if x , y are representatives, how can we implement U NION that works for any x , y ?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 50

lecture_10 - Introduction to Algorithms...

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

View Full Document
Ask a homework question - tutors are online