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.

C-10.1<br />

Design a variation of algorithm TreeSearch for perform<strong>in</strong>g the operation<br />

f<strong>in</strong>dAl(k) <strong>in</strong> an ordered dictionary implemented with a b<strong>in</strong>ary search tree T,<br />

<strong>and</strong> show that it runs <strong>in</strong> time O(h + s), where h is the height of T <strong>and</strong> s is the size<br />

of the collection returned.<br />

C-10.2<br />

Describe how to perform an operation removeAll(k), which removes all the<br />

entries whose keys equal k <strong>in</strong> an ordered dictionary implemented with a b<strong>in</strong>ary<br />

search tree T, <strong>and</strong> show that this method runs <strong>in</strong> time O(h + s), where h is the<br />

height of T <strong>and</strong> s is the size of the iterator returned.<br />

C-10.3<br />

Draw a schematic of an AVL tree such that a s<strong>in</strong>gle remove operation could<br />

require Ω(logn) tr<strong>in</strong>ode restructur<strong>in</strong>gs (or rotations) from a leaf to the root <strong>in</strong><br />

order to restore the height-balance property.<br />

C-10.4<br />

Show how to perform an operation, removeAll(k), which removes all entries<br />

with keys equal to K, <strong>in</strong> a dictionary implemented with an AVL tree <strong>in</strong> time<br />

O(slogn), where n is the number of entries <strong>in</strong> the dictionary <strong>and</strong> s is the size of<br />

the iterator returned.<br />

C-10.5<br />

If we ma<strong>in</strong>ta<strong>in</strong> a reference to the position of the left-most <strong>in</strong>ternal node of an<br />

AVL tree, then operation first (Section 9.5.2) can be performed <strong>in</strong> O(1) time.<br />

Describe how the implementation of the other dictionary methods needs to be<br />

modified to ma<strong>in</strong>ta<strong>in</strong> a reference to the left-most position.<br />

C-10.6<br />

Show that any n-node b<strong>in</strong>ary tree can be converted to any other n-node b<strong>in</strong>ary<br />

tree us<strong>in</strong>g O(n) rotations.<br />

C-10.7<br />

Let D be an ordered dictionary with n entries implemented by means of an AVL<br />

tree. Show how to implement the follow<strong>in</strong>g operation on D <strong>in</strong> time O(logn + s),<br />

where s is the size of the iterator returned:<br />

f<strong>in</strong>dAllInRange(k 1 ,k 2 ): Return an iterator of all the entries <strong>in</strong> D with key k<br />

such that k 1 ≤ k ≤ k 2 .<br />

670

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

Saved successfully!

Ooh no, something went wrong!