18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

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.

Lecture 8 - binary trees<br />

if (x = NIL) and (k = key[x])<br />

if (k < key[x])<br />

then return x<br />

then return TREE-SEARCH(left[x],k)<br />

else return TREE-SEARCH(right[x],k)<br />

<strong>The</strong> algorithm works because both the left and right subtrees of a binary search tree are binary search trees - recursive<br />

structure, recursive algorithm.<br />

This takes time proportional to the height of the tree, O(h).<br />

Listen To Part 8-6<br />

Maximum and Minimum<br />

Where are the maximum and minimum elements in a binary tree?<br />

TREE-MAXIMUM(X)<br />

while<br />

file:///E|/LEC/LECTUR17/NODE8.HTM (3 of 13) [19/1/2003 1:34:46]<br />

do x = right[x]

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

Saved successfully!

Ooh no, something went wrong!