Maps ADT Flashcards

1
Q

Name the 3 properties of a Map as well as a reason for the inspiration of maps

A
  1. A searchable collection of key, value entries
  2. Main operations are searching, inserting and removing
  3. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name 2 applications of the Map ADT

A

A student database

an address book

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name the 3 main functions of a map and a brief definition of each

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write down the pseudo code for the get method

A

get(k){

for each p in S.positions()
if p.element().getKey() == k
return p.element().getValue()

return null
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write down pseudo-code for the put(k,v) method

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write down pseudo-code for the remove(k) method

A

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

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly