# lec16a - Dictionaries Collection of pairs. (key, element)...

This preview shows pages 1–8. Sign up to view the full content.

Dictionaries Collection of pairs. (key, element) Pairs have different keys. Operations. get(theKey) put(theKey, theElement) remove(theKey)

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

View Full Document
Application Collection of student records in this class. (key, element) = (student name, linear list of assignment and exam scores) All keys are distinct. Get the element whose key is John Adams . Update the element whose key is Diana Ross . put() implemented as update when there is already a pair with the given key. remove() followed by put().
Dictionary With Duplicates Keys are not required to be distinct. Word dictionary. Pairs are of the form (word, meaning) . May have two or more entries for the same word. (bolt, a threaded pin) (bolt, a crash of thunder) (bolt, to shoot forth suddenly) (bolt, a gulp) (bolt, a standard roll of cloth) etc.

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

View Full Document
Represent As A Linear List L = (e 0 , e 1 , e 2 , e 3 , …, e n-1 ) Each e i is a pair (key, element) . 5 -pair dictionary D = (a, b, c, d, e) . a = (aKey, aElement) , b = (bKey, bElement), etc. Array or linked representation.
Array Representation a b c d e get(theKey) O(size) time put(theKey, theElement) O(size) time to verify duplicate, O(1) to add at right end. remove(theKey) O(size) time.

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

View Full Document
Sorted Array A B C D E elements are in ascending order of key. get(theKey) O(log size) time put(theKey, theElement) O(log size) time to verify duplicate, O(size) to add. remove(theKey) O(size) time.
get(theKey) O(size) time put(theKey, theElement) O(size) time to verify duplicate, O(1) to add at left end. remove(theKey)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/18/2012 for the course COP 3530 taught by Professor Davis during the Fall '08 term at University of Florida.

### Page1 / 29

lec16a - Dictionaries Collection of pairs. (key, element)...

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

View Full Document
Ask a homework question - tutors are online