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 7.21: (a) Tree T; (b) <strong>in</strong>dented parenthetic<br />

representation of T.<br />

C-7.6<br />

Let T be a (possibly improper) b<strong>in</strong>ary tree with n nodes, <strong>and</strong> let D be the sum of<br />

the depths of all the external nodes of T. Describe a configuration for T such<br />

that D is Ω(n 2 ). Such a tree would be the worst case for the asymptotic runn<strong>in</strong>g<br />

time of Algorithm height1 (Code Fragment 7.5).<br />

C-7.7<br />

For a tree T, let n I denote the number of its <strong>in</strong>ternal nodes, <strong>and</strong> let n E denote the<br />

number of its external nodes. Show that if every <strong>in</strong>ternal node <strong>in</strong> T has exactly 3<br />

children, then n E = 2n I + 1.<br />

C-7.8<br />

Describe how to clone a proper b<strong>in</strong>ary tree us<strong>in</strong>g the attach method <strong>in</strong>stead of<br />

methods <strong>in</strong>sertLeft <strong>and</strong> <strong>in</strong>sertRight.<br />

C-7.9<br />

The balance factor of an <strong>in</strong>ternal node v of a proper b<strong>in</strong>ary tree is the difference<br />

between the heights of the right <strong>and</strong> left subtrees of v. Show how to specialize<br />

the Euler tour traversal of Section 7.3.7 to pr<strong>in</strong>t the balance factors of all the<br />

<strong>in</strong>ternal nodes of a proper b<strong>in</strong>ary tree.<br />

438

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

Saved successfully!

Ooh no, something went wrong!