18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

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.

Dictionaries<br />

Next: Binary Search Trees Up: Fundamental Data Types Previous: Containers<br />

Dictionaries<br />

Dictionaries are a form of container that permits access to data items by content. You put a word into a<br />

dictionary because you know you can look it up when you need it.<br />

<strong>The</strong> primary operations dictionaries support are:<br />

● Search(D,k): Given a search key k, return a pointer to the element in dictionary D whose key<br />

value is k, if one exists.<br />

● Insert(D,x): Given a data item x, add it to the set of items in the dictionary D.<br />

● Delete(D,x): Given a pointer to a given data item x in the dictionary D, remove it from D.<br />

Perhaps the simplest possible dictionary implementation maintains an unsorted linked list as a data<br />

structure. Insertion and deletion are supported in constant time, although a query requires potentially<br />

traversing the entire linked list. Basing an implementation on a stored array speeds up the query<br />

operation to by binary search. Making room for a new item or filling a hole left by a deletion may<br />

require moving arbitrarily many items, so insertion and deletion become linear-time operations.<br />

Many other dictionary implementations are available. Binary search trees are discussed in some detail in<br />

the next section. Hash tables are another attractive option in practice. A complete discussion of different<br />

dictionary data structures is presented catalog Section . We encourage the reader to browse through<br />

the data structures section of the catalog in order to learn what your options are.<br />

Certain dictionary data structures also efficiently support the following useful operations:<br />

● Max(D) or Min(D): Retrieve the item with the largest (or smallest) key from D. This enables the<br />

dictionary to serve as a priority, as discussed below.<br />

● Predecessor(D,k) or Successor(D,k): Retrieve the item from D whose key is immediately before<br />

(or after) k in sorted order. By starting from the first item Min(D) and repeatedly calling Successor<br />

until we obtain Max(D), we traverse all elements in sorted order.<br />

file:///E|/BOOK/BOOK/NODE25.HTM (1 of 2) [19/1/2003 1:28:23]

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

Saved successfully!

Ooh no, something went wrong!