Maps ADT Flashcards
Name the 3 properties of a Map as well as a reason for the inspiration of maps
- A searchable collection of key, value entries
- Main operations are searching, inserting and removing
- Multiple entries with the same key are not allowed
Maps are used to map a key, normally some sort of unique identifier to a specific value. That collection is the searchable
Name 2 applications of the Map ADT
A student database
an address book
Name the 3 main functions of a map and a brief definition of each
remove(k): remove key-value pair return value or null if DNE
put(k,v) : new entry and return null or replace old value and return it
get(k) : return associated value otherwise return null
Write down the pseudo code for the get method
get(k){
for each p in S.positions()
if p.element().getKey() == k
return p.element().getValue()
return null
}
Write down pseudo-code for the put(k,v) method
put (k,v){
for each position p in S.positions() if p.element().getKey() == k t = p.element.getValue() set (k,v) return t
S.addLast((k,v))
S.size++
return null
Write down pseudo-code for the remove(k) method
remove(k){
for each p in S.positions if p.element().getKey() == k t = p.element().getValue() S.remove(p) S.size-- return t
return null
}