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.

6.6 Exercises<br />

For source code <strong>and</strong> help with exercises, please visit<br />

java.datastructures.net.<br />

Re<strong>in</strong>forcement<br />

R-6.1<br />

Draw a representation of an <strong>in</strong>itially empty array list A after perform<strong>in</strong>g the<br />

follow<strong>in</strong>g sequence of operations: add(0,4), add(0,3), add(0,2),<br />

add(2,1), add(1,5), add(1,6), add(3,7), add(0,8).<br />

R-6.2<br />

Give a justification of the runn<strong>in</strong>g times shown <strong>in</strong> Table 6.2 for the methods of<br />

an array list implemented with a (nonexp<strong>and</strong><strong>in</strong>g) array.<br />

R-6.3<br />

Give an adapter class to support the Stack <strong>in</strong>terface us<strong>in</strong>g the methods of the<br />

array list ADT.<br />

R-6.4<br />

Redo the justification of Proposition 6.2 assum<strong>in</strong>g that the the cost of grow<strong>in</strong>g<br />

the array from size k to size 2k is 3k cyber-dollars. How much should each push<br />

operation be charged to make the amortization work?<br />

R-6.5<br />

Give pseudo-code descriptions of algorithms for perform<strong>in</strong>g the methods<br />

addBefore(p,e), addFirst(e), <strong>and</strong> addLast(e) of the node list<br />

ADT, assum<strong>in</strong>g the list is implemented us<strong>in</strong>g a doubly l<strong>in</strong>ked list.<br />

R-6.6<br />

Draw pictures illustrat<strong>in</strong>g each of the major steps <strong>in</strong> the algorithms given <strong>in</strong> the<br />

previous exercise.<br />

R-6.7<br />

Provide the details of an array implementation of the node list ADT, <strong>in</strong>clud<strong>in</strong>g<br />

how to perform the methods add Before <strong>and</strong> addAfter.<br />

R-6.8<br />

365

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

Saved successfully!

Ooh no, something went wrong!