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-6.24<br />

Isabel has an <strong>in</strong>terest<strong>in</strong>g way of summ<strong>in</strong>g up the values <strong>in</strong> an array A of n<br />

<strong>in</strong>tegers, where n is a power of two. She creates an array B of half the size of A<br />

<strong>and</strong> sets B[i] = A[2i] +A[2i+ 1], for i = 0,1,..., (n/2) − 1. If B has size 1, then she<br />

outputs B[0]. Otherwise, she replaces A with B, <strong>and</strong> repeats the process. What is<br />

the runn<strong>in</strong>g time of her algorithm?<br />

Projects<br />

P-6.1<br />

Implement the array list ADT by means of an extendable array used <strong>in</strong> a circular<br />

fashion, so that <strong>in</strong>sertions <strong>and</strong> deletions at the beg<strong>in</strong>n<strong>in</strong>g <strong>and</strong> end of the array list<br />

run <strong>in</strong> constant time.<br />

P-6.2<br />

Implement the array list ADT us<strong>in</strong>g a doubly l<strong>in</strong>ked list. Show experimentally<br />

that this implementation is worse than the array-based approach.<br />

P-6.3<br />

Write a simple text editor, which stores <strong>and</strong> displays a str<strong>in</strong>g of characters us<strong>in</strong>g<br />

the list ADT, together with a cursor object that highlights a position <strong>in</strong> this<br />

str<strong>in</strong>g. Your editor should support the follow<strong>in</strong>g operations:<br />

P-6.4<br />

•<br />

left: Move cursor left one character (do noth<strong>in</strong>g if at text end).<br />

•<br />

right: Move cursor right one character (do noth<strong>in</strong>g if at text end).<br />

•<br />

cut: Delete the character right of the cursor (do noth<strong>in</strong>g at text end).<br />

•<br />

paste c: Insert the character c just after the cursor.<br />

Implement a phased favorites list. A phase consists of N accesses <strong>in</strong> the list, for<br />

a given parameter N. Dur<strong>in</strong>g a phase, the list should ma<strong>in</strong>ta<strong>in</strong> itself so that<br />

elements are ordered by decreas<strong>in</strong>g access counts dur<strong>in</strong>g that phase. At the end<br />

371

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

Saved successfully!

Ooh no, something went wrong!