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.

class). Below, we show how to set up location-aware entries for several data<br />

structures presented <strong>in</strong> this chapter.<br />

• Unordered list : In an unordered list, L, implement<strong>in</strong>g a dictionary, we can<br />

ma<strong>in</strong>ta<strong>in</strong> the location variable of each entry e to po<strong>in</strong>t to e's position <strong>in</strong> the<br />

underly<strong>in</strong>g l<strong>in</strong>ked list for L. This choice allows us to perform remove(e) as<br />

L.remove(e.location()), which would run <strong>in</strong> O(1) time.<br />

• Hash table with separate cha<strong>in</strong><strong>in</strong>g : Consider a hash table,<br />

with bucket array A <strong>and</strong> hash function h, that uses separate cha<strong>in</strong><strong>in</strong>g for h<strong>and</strong>l<strong>in</strong>g<br />

collisions. We use the location variable of each entry e to po<strong>in</strong>t to e's position<br />

<strong>in</strong> the list L implement<strong>in</strong>g the m<strong>in</strong>i-map A[h(k)]. This choice allows us to perform<br />

the ma<strong>in</strong> work of a remove(e) as L.remove(e.location()), which would<br />

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

• Ordered search table : In an ordered table, T, implement<strong>in</strong>g a dictionary,<br />

we should ma<strong>in</strong>ta<strong>in</strong> the location variable of each entry e to be e's <strong>in</strong>dex <strong>in</strong> T.<br />

This choice would allow us to perform remove(e) as<br />

T.remove(e.location()). (Recall that location() now returns an<br />

<strong>in</strong>teger.) This approach would run fast if entry e was stored near the end of T.<br />

• Skip list : In a skip list, S, implement<strong>in</strong>g a dictionary, we should ma<strong>in</strong>ta<strong>in</strong><br />

the location variable of each entry e to po<strong>in</strong>t to e's position <strong>in</strong> the bottom level<br />

of S. This choice would allow us to skip the search step <strong>in</strong> our algorithm for<br />

perform<strong>in</strong>g remove(e) <strong>in</strong> a skip list.<br />

We summarize the performance of entry removal <strong>in</strong> a dictionary with locationaware<br />

entries <strong>in</strong> Table 9.5.<br />

Table 9.5: Performance of the remove method <strong>in</strong><br />

dictionaries implemented with location-aware entries.<br />

We use n to denote the number of entries <strong>in</strong> the<br />

dictionary.<br />

List<br />

Hash Table<br />

Search Table<br />

Skip List<br />

O(1)<br />

O(1) (expected)<br />

568

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

Saved successfully!

Ooh no, something went wrong!