23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

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.

an error occurs if v is an <strong>in</strong>ternal node.<br />

Given this method, we perform <strong>in</strong>sert(k,x) for a dictionary implemented with a<br />

b<strong>in</strong>ary search tree T by call<strong>in</strong>g TreeInsert(k,x,T.root()), which is given <strong>in</strong><br />

Code Fragment 10.2.<br />

Code Fragment 10.2: Recursive algorithm for<br />

<strong>in</strong>sertion <strong>in</strong> a b<strong>in</strong>ary search tree.<br />

This algorithm traces a path from T's root to an external node, which is exp<strong>and</strong>ed<br />

<strong>in</strong>to a new <strong>in</strong>ternal node accommodat<strong>in</strong>g the new entry. An example of <strong>in</strong>sertion<br />

<strong>in</strong>to a b<strong>in</strong>ary search tree is shown <strong>in</strong> Figure 10.3.<br />

Figure 10.3: Insertion of an entry with key 78 <strong>in</strong>to the<br />

search tree of Figure 10.1. F<strong>in</strong>d<strong>in</strong>g the position to<br />

<strong>in</strong>sert is shown <strong>in</strong> (a), <strong>and</strong> the result<strong>in</strong>g tree is shown <strong>in</strong><br />

(b).<br />

Removal<br />

588

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

Saved successfully!

Ooh no, something went wrong!