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.

position <strong>in</strong> the bottom level of the skip list. Thus, the hasNext <strong>and</strong> next<br />

methods of these iterators would each run <strong>in</strong> constant time us<strong>in</strong>g this approach.<br />

The java.util.Sorted Map Interface<br />

<strong>Java</strong> provides an ordered version of the java.util.Map <strong>in</strong>terface <strong>in</strong> its<br />

<strong>in</strong>terface called java.util.SortedMap. This <strong>in</strong>terface extends the<br />

java.util.Map <strong>in</strong>terface with methods that take order <strong>in</strong>to account. Like the<br />

parent <strong>in</strong>terface, a SortedMap does not allow for duplicate keys.<br />

Ignor<strong>in</strong>g the fact that dictionaries allow for multiple entries with the same key,<br />

possible correspondences between methods of our ordered dictionary ADT <strong>and</strong><br />

methods of <strong>in</strong>terface java.util.SortedMap are shown <strong>in</strong> Table 9.6.<br />

Table 9.6: Loose correspondences between<br />

methods of the ordered dictionary ADT <strong>and</strong> methods<br />

of the java.util.SortedMap <strong>in</strong>terface, which<br />

supports other methods as well. The<br />

java.util.SortedMap expression for<br />

predecessors(k) is not an exact correspondence,<br />

however, as the iterator returned would be by<br />

<strong>in</strong>creas<strong>in</strong>g keys <strong>and</strong> would not <strong>in</strong>clude the entry with<br />

key equal to k. There appears to be no efficient way of<br />

gett<strong>in</strong>g a true correspondence to predecessors(k)<br />

us<strong>in</strong>g java.util.SortedMap methods.<br />

Ordered Dictionary Methods<br />

java.util.SortedMap Methods<br />

first().getKey()<br />

firstKey()<br />

first().getValue()<br />

get(firstKey())<br />

last().getKey()<br />

570

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

Saved successfully!

Ooh no, something went wrong!