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.

Describe a nonrecursive method for perform<strong>in</strong>g an Euler tour traversal of a<br />

b<strong>in</strong>ary tree that runs <strong>in</strong> l<strong>in</strong>ear time <strong>and</strong> does not use a stack.<br />

C-7.29<br />

Describe, <strong>in</strong> pseudo-code, a nonrecursive method for perform<strong>in</strong>g an <strong>in</strong>-order<br />

traversal of a b<strong>in</strong>ary tree <strong>in</strong> l<strong>in</strong>ear time.<br />

C-7.30<br />

Let T be a b<strong>in</strong>ary tree with n nodes (T may be realized with an array list or a<br />

l<strong>in</strong>ked structure). Give a l<strong>in</strong>ear-time algorithm that uses the methods of the<br />

B<strong>in</strong>ary Tree <strong>in</strong>terface to traverse the nodes of T by <strong>in</strong>creas<strong>in</strong>g values of the level<br />

number<strong>in</strong>g function p given <strong>in</strong> Section 7.3.5. This traversal is known as the level<br />

order traversal.<br />

C-7.31<br />

The path length of a tree T is the sum of the depths of all the nodes <strong>in</strong> T.<br />

Describe a l<strong>in</strong>ear-time method for comput<strong>in</strong>g the path length of a tree T (which<br />

is not necessarily b<strong>in</strong>ary).<br />

C-7.32<br />

Def<strong>in</strong>e the <strong>in</strong>ternal path length, I(T), of a tree T to be the sum of the depths of<br />

all the <strong>in</strong>ternal nodes <strong>in</strong> T. Likewise, def<strong>in</strong>e the external path length, E(T), of a<br />

tree T to be the sum of the depths of all the external nodes <strong>in</strong> T. Show that if T is<br />

a proper b<strong>in</strong>ary tree with n nodes, then E(T) = I(T) + n − 1.<br />

Projects<br />

P-7.1<br />

Implement the b<strong>in</strong>ary tree ADT us<strong>in</strong>g an array list.<br />

P-7.2<br />

Implement the tree ADT us<strong>in</strong>g a l<strong>in</strong>ked structure.<br />

P-7.3<br />

Write a program that draws a b<strong>in</strong>ary tree.<br />

P-7.4<br />

Write a program that draws a general tree.<br />

P-7.5<br />

443

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

Saved successfully!

Ooh no, something went wrong!