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.

Provide <strong>Java</strong> code fragments for the methods of the PositionList <strong>in</strong>terface<br />

of Code Fragment 6.5 that are not <strong>in</strong>cluded <strong>in</strong> Code Fragments 6.9-6.11.<br />

R-6.9<br />

Describe a nonrecursive method for revers<strong>in</strong>g a node list represented with a<br />

doubly l<strong>in</strong>ked list us<strong>in</strong>g a s<strong>in</strong>gle pass through the list (you may use the <strong>in</strong>ternal<br />

node po<strong>in</strong>ters).<br />

R-6.10<br />

Given the set of element {a, b, c, d, e, f} stored <strong>in</strong> a list, show the f<strong>in</strong>al state of<br />

the list, assum<strong>in</strong>g we use the move-to-front heuristic <strong>and</strong> access the elements<br />

accord<strong>in</strong>g to the follow<strong>in</strong>g sequence: (a, b, c, d, e, f, a, c, f,b,d,e).<br />

R-6.11<br />

Suppose we are keep<strong>in</strong>g track of access counts <strong>in</strong> a list L of n elements. Suppose<br />

further that we have made kn total accesses to the elements <strong>in</strong> L, for some<br />

<strong>in</strong>teger k ≥ 1. What are the m<strong>in</strong>imum <strong>and</strong> maximum number of elements that<br />

have been accessed fewer than k times?<br />

R-6.12<br />

Give pseudo-code describ<strong>in</strong>g how to implement all the operations <strong>in</strong> the array<br />

list ADT us<strong>in</strong>g an array <strong>in</strong> a circular fashion. What is the runn<strong>in</strong>g time for each<br />

of these methods?<br />

R-6.13<br />

Us<strong>in</strong>g the Sequence <strong>in</strong>terface methods, describe a recursive method for<br />

determ<strong>in</strong><strong>in</strong>g if a sequence S of n <strong>in</strong>tegers conta<strong>in</strong>s a given <strong>in</strong>teger k. Your<br />

method should not conta<strong>in</strong> any loops. How much space does your method use <strong>in</strong><br />

addition to the space used for S?<br />

R-6.14<br />

Briefly describe how to perform a new sequence method makeFirst(p) that<br />

moves an element of a sequence S at position p to be the first element <strong>in</strong> S while<br />

keep<strong>in</strong>g the relative order<strong>in</strong>g of the rema<strong>in</strong><strong>in</strong>g elements <strong>in</strong> S unchanged. That is,<br />

makeFirst(p) performs a move-to-front. Your method should run <strong>in</strong> O(1)<br />

time if S is implemented with a doubly l<strong>in</strong>ked list.<br />

R-6.15<br />

Describe how to use an array list <strong>and</strong> an <strong>in</strong>t field to implement an iterator.<br />

Include pseudo-code fragments describ<strong>in</strong>g hasNext() <strong>and</strong> next().<br />

366

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

Saved successfully!

Ooh no, something went wrong!