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

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

View Full Document Right Arrow Icon
Dictionaries Collection of pairs. (key, element) Pairs have different keys. Operations. get(theKey) put(theKey, theElement) remove(theKey)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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().
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
get(theKey) O(size) time put(theKey, theElement) O(size) time to verify duplicate, O(1) to add at left end. remove(theKey)
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
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 Right Arrow Icon
Ask a homework question - tutors are online