24.12.2013 Views

․Course ․Readings:

Unit-3.pdf

Unit-3.pdf

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.

Tree Insertion<br />

․Insert z into tree T.<br />

Tree-Insert(T, z)<br />

1. y = NIL<br />

2. x = T.root<br />

3. while x NIL<br />

4. y = x<br />

5. if z.key < x.key<br />

6. x = x.left<br />

7. else x = x.right<br />

8. z.p = y<br />

9. if y == NIL<br />

10. T.root = z // T is<br />

empty<br />

11. elseif z.key < y.key<br />

12. y.left = z<br />

13. else y.right = z<br />

4<br />

xy<br />

x<br />

z<br />

xy<br />

Unit 3 Spring 2013<br />

5

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

Saved successfully!

Ooh no, something went wrong!