30.12.2013 Views

Red-Black tree Rotation, Insertion, Deletion

Red-Black tree Rotation, Insertion, Deletion

Red-Black tree Rotation, Insertion, Deletion

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

To get a linear algorithm, wemust beware of <strong>tree</strong>s like:<br />

1<br />

7<br />

2<br />

3<br />

4<br />

8<br />

9<br />

10<br />

2<br />

11<br />

12 1<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

5<br />

6<br />

The correct answer is n ; 1 rotations suce to get to<br />

a rightmost chain.<br />

By picking the lowest node on the rightmost chain<br />

which has a left ancestor, we can add one node per<br />

rotation to the right most chain!<br />

zz<br />

y<br />

y<br />

x<br />

zz<br />

x<br />

z<br />

z<br />

Initially, the rightmost chain contained at least 1 node,<br />

so after n ; 1 rotations it contains all n. Slick!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!