1 / 5

Hashing

Hashing. Basic Technique Open Hashing Closed Hashing Restructuring Hash Tables. Hashing. Basic Technique Hash Function – h(x) : X  (0, 1, ... , b-1) Given an object x, calculate an “equivalence class” h1(x) = x mod b h2(x) = floor(x / 10) mod b

rebekah
Télécharger la présentation

Hashing

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 Basic Technique Open Hashing Closed Hashing Restructuring Hash Tables CS 303 – Hashing Lecture 11

  2. Hashing • Basic Technique • Hash Function – h(x) : X  (0, 1, ... , b-1) • Given an object x, calculate an “equivalence class” • h1(x) = x mod b • h2(x) = floor(x / 10) mod b • h3(s) = ( ord(ci) ) mod b • Desiderata • h should “hash” x so that: • |B0| = |B1| = .... = |Bb-1| • x’s should be “randomly” (but repeatably!) dispersed (fast) • May need to use domain specific information about the distribution of values for x CS 303 – Hashing Lecture 11

  3. Open Hashing Set of Sets • Member • calculate h(x) • scan list B(h(x)) • Insert • calculate h(x) • add to B(h(x)) • Delete • calculate h(x) • remove from B(h(x)) • Ideally, the lists B(i) are short and uniform in length • O(N/B) [NOT O(1)!] ... 1 2 ... ... b-1 CS 303 – Hashing Lecture 11

  4. Closed Hashing • No linked lists – just the table! • Note 0-based addressing • Search • calculate h(x) • inspect B(h(x)) • if FULL and B(h).v = x • then FOUND • else ReHash with hi(x) • Strategies • LINEAR – hi+1(x) = hi(x) + 1 mod b • RANDOM – new hi(x) every time? 0 e is one of: EMPTY DELETED FULL i b-1 CS 303 – Hashing Lecture 11

  5. Restructuring Hash Tables Insertion 1/(1-a) • For Closed Hashing • Slow growth until a = 0.8, then explosive growth • If a 0.9 (closed) or N/B  2 (open) it pays to • 1) create a new table with B’ = 2B • 2) re-insert all elements into the new table Deletion -(1/a)log(1-a) a 0.8 CS 303 – Hashing Lecture 11

More Related