Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hashing for dummies 1 For quick search, insert and delete of data from a table. 1 figures and concepts from MITOPENCOURSEWARE

Similar presentations


Presentation on theme: "Hashing for dummies 1 For quick search, insert and delete of data from a table. 1 figures and concepts from MITOPENCOURSEWARE"— Presentation transcript:

1 Hashing for dummies 1 For quick search, insert and delete of data from a table. 1 figures and concepts from MITOPENCOURSEWARE http://videolectures.net/mit6046jf05_leiserson_lec07/

2 Hashing function

3 Collisions

4 Hash Cases Worst case –All key “hashes” to same slot Built a fancy linked list Best case –assumption of simple uniform hashing Each key is equally likely to be hashed to any slot of table T, independent of where other keys are hashed.

5 Search times Unsuccessful search –Calculate hash function + Search list of average size (load factor) Successful –Calculate has function + search of list average size + 1 /2 Order 1 ~ constant time assuming uniform hashing

6 Choosing hash function Characteristics –Distribute keys uniformly into slots –Regularity in key distribution should not affect uniformity Division method –H(k) = k mod m (m # of slots) –all even #s to hash only hashes into even slots & odd slots aren’t used

7 Hash function example Example ASCII # for first letter –Jones (74), Williams (87), Smith (83), Davis (68), Kelly (75), Garcia (71), Lo (76), Moon (77) Table size m = 5 H(74) = 74 mod 5  4 H(87) = 87 mod 5  2 H(83) = 83 mod 5  3 H(68) = 68 mod 5  3 H(75) = 75 mod 5  0 H(71) = 71 mod 5  1 H(76) = 76 mod 5  1 H(77) = 77 mod 5  2 0 1 2 3 4 -Kelly -Garcia - Lo -Williams - Moon -Smith - Davis - Jones


Download ppt "Hashing for dummies 1 For quick search, insert and delete of data from a table. 1 figures and concepts from MITOPENCOURSEWARE"

Similar presentations


Ads by Google