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 an <strong>in</strong>-place version of the selection-sort algorithm that uses only O(1)<br />

space for <strong>in</strong>stance variables <strong>in</strong> addition to an <strong>in</strong>put array itself.<br />

C-8.8<br />

Assum<strong>in</strong>g the <strong>in</strong>put to the sort<strong>in</strong>g problem is given <strong>in</strong> an array A, describe how<br />

to implement the <strong>in</strong>sertion-sort algorithm us<strong>in</strong>g only the array A <strong>and</strong>, at most,<br />

six additional (base-type) variables.<br />

C-8.9<br />

Describe how to implement the heap-sort algorithm us<strong>in</strong>g, at most, six <strong>in</strong>teger<br />

variables <strong>in</strong> addition to an <strong>in</strong>put array itself.<br />

C-8.10<br />

Describe a sequence of n <strong>in</strong>sertions <strong>in</strong> a heap that requires Ω(nlogn) time to<br />

process.<br />

C-8.11<br />

An alternative method for f<strong>in</strong>d<strong>in</strong>g the last node dur<strong>in</strong>g an <strong>in</strong>sertion <strong>in</strong> a heap T is<br />

to store, <strong>in</strong> the last node <strong>and</strong> each external node of T, a reference to the external<br />

node immediately to its right (wrapp<strong>in</strong>g to the first node <strong>in</strong> the next lower level<br />

for the right-most external node). Show how to ma<strong>in</strong>ta<strong>in</strong> such references <strong>in</strong> O(1)<br />

time per operation of the priority queue ADT assum<strong>in</strong>g T is implemented as a<br />

l<strong>in</strong>ked structure.<br />

C-8.12<br />

Describe an implementation of complete b<strong>in</strong>ary tree T by means of a l<strong>in</strong>ked<br />

structure <strong>and</strong> a reference to the last node. In particular, show how to update the<br />

reference to the last node after operations add <strong>and</strong> remove <strong>in</strong> O(logn) time,<br />

where n is the current number of nodes of T. Be sure <strong>and</strong> h<strong>and</strong>le all possible<br />

cases, as illustrated <strong>in</strong> Figure 8.12.<br />

Figure 8.12: Updat<strong>in</strong>g the last node <strong>in</strong> a complete<br />

b<strong>in</strong>ary tree after operation add or remove. Node w is<br />

the last node before operation add or after operation<br />

remove. Node z is the last node after operation add or<br />

before operation remove.<br />

508

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

Saved successfully!

Ooh no, something went wrong!