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.

<strong>in</strong> memory, describe a method runn<strong>in</strong>g <strong>in</strong> O(n logn) time (not O(n 2 ) time!) for<br />

count<strong>in</strong>g the number of 1's <strong>in</strong> A.<br />

C-9.14<br />

Describe an efficient dictionary structure for stor<strong>in</strong>g n entries that have an<br />

associated set of r < n keys that comes from a total order. That is, the set of keys<br />

is smaller than the number of entries. Your structure should perform operation<br />

f<strong>in</strong>d All <strong>in</strong> O(logr + s) expected time, where s is the number of entries<br />

returned, operation entries() <strong>in</strong> O(n) time, <strong>and</strong> the rema<strong>in</strong><strong>in</strong>g operations of<br />

the dictionary ADT <strong>in</strong> O(logr) expected time.<br />

C-9.15<br />

Describe an efficient dictionary structure for stor<strong>in</strong>g n entries whose r < n keys<br />

have dist<strong>in</strong>ct hash codes. Your structure should perform operation f<strong>in</strong>dAll <strong>in</strong><br />

O(1 + s) expected time, where s is the number of entries returned, operation<br />

entries() <strong>in</strong> O(n) time, <strong>and</strong> the rema<strong>in</strong><strong>in</strong>g operations of the dictionary ADT<br />

<strong>in</strong> O(1) expected time.<br />

C-9.16<br />

Describe an efficient data structure for implement<strong>in</strong>g the bag ADT, which<br />

supports a method add(e), for add<strong>in</strong>g an element e to the bag, <strong>and</strong> a method<br />

remove(), which removes an arbitrary element <strong>in</strong> the bag. Show that both of<br />

these methods can be done <strong>in</strong> O(1) time.<br />

C-9.17<br />

Describe how to modify the skip list data structure to support the method<br />

atIndex(i), which returns the position of the element <strong>in</strong> the "bottom" list S 0 at<br />

<strong>in</strong>dex i, for i [0, n − 1]. Show that your implementation of this method runs <strong>in</strong><br />

O(logn) expected time.<br />

Projects<br />

P-9.1<br />

Implement a class that implements the dictionary ADT by adapt<strong>in</strong>g the<br />

java.util.HashMap class.<br />

P-9.2<br />

Implement the map ADT with a hash table with separate cha<strong>in</strong><strong>in</strong>g collision<br />

h<strong>and</strong>l<strong>in</strong>g (do not adapt any java.util classes).<br />

P-9.3<br />

579

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

Saved successfully!

Ooh no, something went wrong!