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.

Let T be an n-node b<strong>in</strong>ary tree that may be improper. Describe how to represent<br />

T by means of a proper b<strong>in</strong>ary tree T ′ with O(n) nodes.<br />

R-7.4<br />

What are the m<strong>in</strong>imum <strong>and</strong> maximum number of <strong>in</strong>ternal <strong>and</strong> external nodes <strong>in</strong><br />

an improper b<strong>in</strong>ary tree with n nodes?<br />

R-7.5<br />

Show a tree achiev<strong>in</strong>g the worst-case runn<strong>in</strong>g time for algorithm depth.<br />

R-7.6<br />

Give a justification of Proposition 7.4.<br />

R-7.7<br />

What is the runn<strong>in</strong>g time of algorithm height2(T, v) (Code Fragment 7.6)<br />

when called on a node v dist<strong>in</strong>ct from the root of T?<br />

R-7.8<br />

Let T be the tree of Figure 7.3, <strong>and</strong> refer to Code Fragments 7.9 <strong>and</strong> 7.10.<br />

a.<br />

Give the output of toStr<strong>in</strong>gPostorder(T, T.root()).<br />

b.<br />

R-7.9<br />

Give the output of parentheticRepresentation(T, T.root()).<br />

Describe a modification to parentheticRepresentation, from Code<br />

Fragment 7.10, so that it uses the length() method for Str<strong>in</strong>g objects to<br />

output the parenthetic representation of a tree with l<strong>in</strong>e breaks <strong>and</strong> spaces added<br />

to display the tree <strong>in</strong> a text w<strong>in</strong>dow that is 80 characters wide.<br />

R-7.10<br />

Draw an arithmetic expression tree that has four external nodes, stor<strong>in</strong>g the<br />

numbers 1, 5, 6, <strong>and</strong> 7 (with each number stored <strong>in</strong> a dist<strong>in</strong>ct external node, but<br />

not necessarily <strong>in</strong> this order), <strong>and</strong> has three <strong>in</strong>ternal nodes, each stor<strong>in</strong>g an<br />

operator from the set { + , − , ×, /}, so that the value of the root is 21. The<br />

operators may return <strong>and</strong> act on fractions, <strong>and</strong> an operator may be used more<br />

than once.<br />

433

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

Saved successfully!

Ooh no, something went wrong!