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.

postorderDraw is similar to preorderDraw but assigns x-coord<strong>in</strong>ates<br />

us<strong>in</strong>g a postorder traversal.<br />

a. Show that the draw<strong>in</strong>g of T produced by preorderDraw has no pairs of<br />

cross<strong>in</strong>g edges.<br />

b. Redraw the b<strong>in</strong>ary tree of Figure 7.19 us<strong>in</strong>g preorderDraw.<br />

c. Show that the draw<strong>in</strong>g of T produced by postorderDraw has no pairs<br />

of cross<strong>in</strong>g edges.<br />

d. Redraw the b<strong>in</strong>ary tree of Figure 7.19 us<strong>in</strong>g postorderDraw.<br />

C-7.16<br />

Design an algorithm for draw<strong>in</strong>g general trees that generalizes the <strong>in</strong>order<br />

traversal approach for draw<strong>in</strong>g b<strong>in</strong>ary trees.<br />

C-7.17<br />

Let a visit action <strong>in</strong> the Euler tour traversal be denoted by a pair (v,a), where v is<br />

the visited node <strong>and</strong> a is one of left, below, or right. Design <strong>and</strong> analyze an<br />

algorithm for perform<strong>in</strong>g operation tourNext(v, a), which returns the visit<br />

action (w,b) follow<strong>in</strong>g (v,a).<br />

C-7.18<br />

Consider a variation of the l<strong>in</strong>ked data structure for b<strong>in</strong>ary trees where each<br />

node object has references to the node objects of the children but not to the node<br />

object of the parent. Describe an implementation of the methods of a b<strong>in</strong>ary tree<br />

with this data structure <strong>and</strong> analyze the time complexity for these methods.<br />

C-7.19<br />

Design an alternative implementation of the l<strong>in</strong>ked data structure for proper<br />

b<strong>in</strong>ary trees us<strong>in</strong>g a class for nodes that specializes <strong>in</strong>to subclasses for an<br />

<strong>in</strong>ternal node, an external node, <strong>and</strong> the root node.<br />

C-7.20<br />

With<strong>in</strong> the l<strong>in</strong>ked data structure for b<strong>in</strong>ary trees, explore an alternative design<br />

for implement<strong>in</strong>g the iterators returned by the methods iterator(),<br />

positions().iterator(), <strong>and</strong> children(v).iterator() such that each<br />

of these methods takes O(1) time. Can you still achieve constant time<br />

implementations for the methods hasNext() <strong>and</strong> next() of the iterators<br />

returned?<br />

C-7.21<br />

441

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

Saved successfully!

Ooh no, something went wrong!