Your SlideShare is downloading. ×
Hashing
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Hashing

76
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
76
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Hashing
  • 2. What is hashing• Simply, generating a numeric key using an algorithm (hash function)• Definition: A function that maps keys to integers, usually to get an even distribution on a smaller set of values.• The very simplest hash function is to use the modulus operator %• Input range % key range
  • 3. Input and key range• Example. We want to store 7 digit telephone numbers so that they can be quickly retrieved. – Number of expected entries = 100 – Range of telephone numbers = 0 – 9999999 Simple hashing algorithm hash = inputNumber % 100 What’s the effect?
  • 4. Applications of hashing• File management – working out where to store records• Comparing complex values• Cryptography – creating digital signatures – eg: md5
  • 5. Collisions• Where the hash value returned for two keys is the same.• What to do? – Open hashing – Closed hashing – Deleting• The 2/3rds rule
  • 6. Closed Hashing1 23 32 44 End234 33 Hash table is supplemented by5 a linked list, which is used to store colliding entries.67 Therefore, some values are found outside of the standard hash table (in the linked list)
  • 7. ‘Open’ Hashing Some strategy is used to fit colliding entries in a predictable way inside the1 23 existing table2 323 44 For this to work, the size of4 33 the table needs to be5 significantly bigger than the total number of records67 At least 3:2
  • 8. DJB Hash function• “An algorithm produced by Professor Daniel J. Bernstein and shown first to the world on the usenet newsgroup comp.lang.c. It is one of the most efficient hash functions ever published. “def DJBHash(key): hash = 5381 for i in range(len(key)): hash = ((hash << 5) + hash) + ord(key[i]) return hash