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.

.<br />

Give the output of pr<strong>in</strong>tExpression(T, T.root()) (Code Fragment<br />

7.27).<br />

R-7.21<br />

Describe, <strong>in</strong> pseudo-code, an algorithm for comput<strong>in</strong>g the number of<br />

descendents of each node of a b<strong>in</strong>ary tree. The algorithm should be based on the<br />

Euler tour traversal.<br />

R-7.22<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. Show that if T has the m<strong>in</strong>imum<br />

number of external nodes possible, then D is O(n) <strong>and</strong> if T has the maximum<br />

number of external nodes possible, then D is O(n log n).<br />

R-7.23<br />

Let T be a b<strong>in</strong>ary tree with n nodes, <strong>and</strong> let p be the level number<strong>in</strong>g of the<br />

nodes of T, as given <strong>in</strong> Section 7.3.5.<br />

a.<br />

Show that, for every node v of T, p(v) ≤ 2 n − 1.<br />

b.<br />

Show an example of a b<strong>in</strong>ary tree with seven nodes that atta<strong>in</strong>s the above<br />

upper bound on p(v) for some node v.<br />

R-7.24<br />

Show how to use the Euler tour traversal to compute the level number, def<strong>in</strong>ed<br />

<strong>in</strong> Section 7.3.5, of each node <strong>in</strong> a b<strong>in</strong>ary tree T.<br />

R-7.25<br />

Draw the b<strong>in</strong>ary tree representation of the follow<strong>in</strong>g arithmetic expression: "(((5<br />

+ 2) * (2 − 1))/((2 + 9) + ((7 − 2) − 1)) * 8)".<br />

R-7.26<br />

Let T be a b<strong>in</strong>ary tree with n nodes that is realized with an array list, S, <strong>and</strong> let p<br />

be the level number<strong>in</strong>g of the nodes <strong>in</strong> T, as given <strong>in</strong> Section 7.3.5. Give<br />

pseudo-code descriptions of each of the methods root, parent, left,<br />

right, hasLeft, hasRight, isInternal, isExternal, <strong>and</strong> isRoot.<br />

436

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

Saved successfully!

Ooh no, something went wrong!