CC2203-Les14Hash-for-viewing

CC2203-Les14Hash-for-viewing - 14-1/14Lesson 14...

Info iconThis preview shows pages 1–6. 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: 14-1/14Lesson 14: Hashing14-2/14Hash Tables• Worst-case time for get, put, and remove is O(size).• Expected time is O(1).14-3/14Ideal Hashing• Uses a 1D array (or table) table[0:b-1].– Each position of this array is a bucket.– A bucket can normally hold only one dictionary pair.• Uses a hash function f that converts each key k into an index in the range [0, b-1].– f(k) is the home bucket for key k.• Every dictionary pair (key, element) is stored in its home bucket table[f[key]].14-4/14[0][1][2][3][4][5][6][7]Ideal Hashing Example• Pairs are: (22,a), (33,c), (3,d), (73,e), (85,f).• Hash table is table[0:7], b = 8.• Hash function is key/11. • Pairs are stored in table as below:(85,f)(22,a) (33,c)(3,d)(73,e)• get, put, and remove take O(1) time.14-5/14What Can Go Wrong?• Where does (26,g) go?• Keys that have the same home bucket are synonyms.– 22 and 26 are synonyms with respect to the hash function that is in use....
View Full Document

This note was uploaded on 08/18/2011 for the course COMP 3868 taught by Professor Keithchan during the Summer '97 term at Hong Kong Polytechnic University.

Page1 / 14

CC2203-Les14Hash-for-viewing - 14-1/14Lesson 14...

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

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