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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C-8.18<br />

Suppose two b<strong>in</strong>ary trees, T 1 <strong>and</strong> T 2 , hold entries satisfy<strong>in</strong>g the heap-order<br />

property. Describe a method for comb<strong>in</strong><strong>in</strong>g T 1 <strong>and</strong> T 2 <strong>in</strong>to a tree T whose<br />

<strong>in</strong>ternal nodes hold the union of the entries <strong>in</strong> T 1 <strong>and</strong>T 2 <strong>and</strong> also satisfy the<br />

heap-order property. Your algorithm should run <strong>in</strong> time O(h 1 + h 2 ) where h 1<br />

<strong>and</strong> h 2 are the respective heights of T 1 <strong>and</strong> T 2 .<br />

C-8.19<br />

Give an alternative analysis of bottom-up heap construction by show<strong>in</strong>g the<br />

follow<strong>in</strong>g summation is O(1), for any positive <strong>in</strong>teger h:<br />

C-8.20<br />

Give an alternate description of the <strong>in</strong>-place heap-sort algorithm that uses a<br />

st<strong>and</strong>ard comparator <strong>in</strong>stead of a reverse one.<br />

C-8.21<br />

Describe efficient algorithms for perform<strong>in</strong>g operations remove(e) <strong>and</strong><br />

replaceKey(e,k) on an adaptable priority queue realized by means of an<br />

unsorted list with location-aware entries.<br />

C-8.22<br />

Describe efficient algorithms for perform<strong>in</strong>g operations remove(e) <strong>and</strong><br />

replaceKey(e,k) on an adaptable priority queue realized by means of a heap<br />

with location-aware entries.<br />

C-8.23<br />

Let S be a set of n po<strong>in</strong>ts <strong>in</strong> the plane with dist<strong>in</strong>ct <strong>in</strong>teger x- <strong>and</strong> y- coord<strong>in</strong>ates.<br />

Let T be a complete b<strong>in</strong>ary tree stor<strong>in</strong>g the po<strong>in</strong>ts from S at its external nodes,<br />

such that the po<strong>in</strong>ts are ordered left-to-right by <strong>in</strong> creas<strong>in</strong>g x-coord<strong>in</strong>ates. For<br />

each node v <strong>in</strong> T, let S(v) denote the subset of S consist<strong>in</strong>g of po<strong>in</strong>ts stored <strong>in</strong> the<br />

subtree rooted at v. For the root r of T, def<strong>in</strong>e top(r) to be the po<strong>in</strong>t <strong>in</strong> S = S(r)<br />

with maximum y-coord<strong>in</strong>ate. For every other node v, def<strong>in</strong>e top(r) to be the<br />

po<strong>in</strong>t <strong>in</strong> S with highest y-coord<strong>in</strong>ate <strong>in</strong> S(v) that is not also the highest y-<br />

coord<strong>in</strong>ate <strong>in</strong> S(u), where u is the parent of v <strong>in</strong> T (if such a po<strong>in</strong>t exists). Such<br />

label<strong>in</strong>g turns T <strong>in</strong>to a priority search tree. Describe a l<strong>in</strong>ear-time algorithm for<br />

turn<strong>in</strong>g T <strong>in</strong>to a priority search tree.<br />

Projects<br />

510

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

Saved successfully!

Ooh no, something went wrong!