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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 10.4: Removal from the b<strong>in</strong>ary search tree of<br />

Figure 10.3b, where the entry to remove (with key 32)<br />

is stored at a node (w) with an external child: (a)<br />

before the removal; (b) after the removal.<br />

Figure 10.5: Removal from the b<strong>in</strong>ary search tree of<br />

Figure 10.3b, where the entry to remove (with key 65)<br />

is stored at a node (w) whose children are both<br />

<strong>in</strong>ternal: (a) before the removal; (b) after the removal.<br />

Performance of a B<strong>in</strong>ary Search Tree<br />

The analysis of the search, <strong>in</strong>sertion, <strong>and</strong> removal algorithms are similar. We<br />

spend O(1) time at each node visited, <strong>and</strong>, <strong>in</strong> the worst case, the number of nodes<br />

visited is proportional to the height h of T. Thus, <strong>in</strong> a dictionary D implemented<br />

with a b<strong>in</strong>ary search tree T, the f<strong>in</strong>d, <strong>in</strong>sert, <strong>and</strong> remove methods run <strong>in</strong><br />

590

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

Saved successfully!

Ooh no, something went wrong!