lec17+18 - 17-1/44•The Map ADT•Implementations of the...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 17-1/44•The Map ADT•Implementations of the Map ADT•Hashing and Hash Tables•Collisions and Collision Resolution Strategies•Hash Functions•Hash Table time costsCSE 12The Map Abstract Data Type17-2/44The Map ADT•The other ADT's we have talked about are container structures intended to hold data of a certain type•The ADT’s operations deal with objects of that type, sometimes called keys: adding them, removing them, checking if the data structure contains them, iterating over them, etc.•The Map ADT has a slightly different emphasis: it is intended to hold pairsof data of certain types•Map operations deal with <key,value> pairs: adding a pair, removing a pair given its key, returning the value of a pair given its key, iterating over the keys or values or pairs, etc.•Map is also sometimes known as: Table, Dictionary, Associative Memory17-3/44Examples of Map Applications•dictionary – a set of words, each one associated with its definition: <word,definition> pairs•book index – collection of key words, each one associated with the page numbers on which the word appears: <keyword,list-of-pages> pairs•symbol table – a compiler data structure associating identifiers with declaration information: <identifier,declaration-information> pairs...Can you think of others?A mapis a collection type that stores 〈key, value〉pairs. A value associated with a key is retrieved by supplying the map with the key. 17-4/44Map Description, Properties & AttributesDescriptionA map stores <key, value> pairs. Given a key, a map provides the value associated with that key. The types of the key and value are such that it must be possible to test for equality among keys and among values.Properties1.Duplicate keys are not allowed.2.A key may be associated with only one value.3.A value may be associated with more than one key.4.Keys can be compared to one another for equality; similarly for values.5.Null keys and values are not allowed.Attributessize: The number of <key, value> pairs in this map.17-5/44Map OperationsMap()pre-condition: noneresponsibilities:constructor—create an empty mappost-condition: size is set to 0returns: nothingput( KeyType key, ValueType value )pre-condition: key and value are not nullkey can be compared for equality to other keys in this mapvalue can be compared for equality to other values in this mapresponsibilities: puts the <key, value> pair into the map. If key already exists in this map, its value is replaced with the new valuepost-condition: size is increased by one if key was not already in this mapreturns: null if key was not already in this map, the old value associated with key otherwiseexception: if key or value is null or cannot be compared to keys/values in this map17-6/44Map Operationsget( KeyType key )pre-condition: key is not null and can be compared for equality to other keys in this mapresponsibilities:gets the value associated with key in this mappost-condition:the map is unchangedreturns: null if key was not found in this map, the value associated...
View Full Document

This note was uploaded on 06/15/2011 for the course ECON 1 taught by Professor Aben during the Fall '07 term at City College of San Francisco.

Page1 / 44

lec17+18 - 17-1/44•The Map ADT•Implementations of the...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online