1 / 7

Hashing for dummies 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/. Hashing function. Collisions. Hash Cases. Worst case All key “hashes” to same slot

Télécharger la présentation

Hashing for dummies 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hashing for dummies1 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 • Kelly • -Garcia - Lo • Williams - Moon • Smith - Davis • Jones 0 1 2 3 4

More Related