Dictionaries and Keyed Dictionaries Flashcards
What is a dictionary?
A type of container ADT which supports certain operations
What type of operations can a dictionary support?
- insert(x)
- deleteItem()
- search(x)- set the current item in the container to be x
- obtain(x)- get the item that matches item x
- delete(x)-delete the item that matches item x
- insert(x)-insert the item x into the container
- Supports a cursor, which can only be affected by using search()
*Note that deleteItem() can only remove the current item, whereas delete(X) can remove any arbitrary item x
What are keyed dictionaries?
Keyed dictionaries are dictionaries that can store items with a special property called a key that is used as an identifier for a section of the dictionary
Why do we need keyed data for keyed dictionaries?
To use compound data with dictionary ADTs that have efficient search capabilities, we need to be able to tell whether one compound data item is larger or smaller than
another
List Keyed Dictionary Operations
- obtain(k) — get the entire item that has key k
- delete(k) — remove from the container the item that has key k
- has(k) — test whether the container has an item with key k
- search(k) — position the cursor at the item with key k
- setItem(x) — If the item at the cursor and x have the same key, replace the item at the cursor
with x
What is the main advantage of a keyed dictionary?
Can search for and delete items from the dictionary with knowledge of only the item’s key, rather than the entire item