hashing
Download
Skip this Video
Download Presentation
Hashing

Loading in 2 Seconds...

play fullscreen
1 / 5

Hashing - PowerPoint PPT Presentation


  • 180 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Hashing' - rebekah


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
hashing

Hashing

Basic Technique

Open Hashing

Closed Hashing

Restructuring Hash Tables

CS 303 – Hashing

Lecture 11

hashing2
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

open hashing
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

closed hashing
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

restructuring hash tables
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

ad