lecture_10

lecture_10 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 10 Prof. Piotr Indyk
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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 –L e t z be the sibling of y . –A s s u m e z is the right sibling of y , otherwise the code is symmetric. –I f 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 * ) –E l s e Update max of y , p(y) , p(p(y)) and so on until root Else If root has only one child u Remove root •M a k e u the new root * Note that the input of Delete does not have to be a leaf x z y
Background image of page 8
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)
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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 .
Background image of page 11

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

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

This note was uploaded on 04/10/2008 for the course CSE 6.046J/18. taught by Professor Piotrindykandcharlese.leiserson during the Fall '04 term at MIT.

Page1 / 50

lecture_10 - Introduction to Algorithms...

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

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