SlideShare a Scribd company logo
Hashing
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
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?
Applications of hashing
• File management – working out where
  to store records
• Comparing complex values
• Cryptography – creating digital
  signatures – eg: md5
Collisions
• Where the hash value returned for two
  keys is the same.

• What to do?
  – Open hashing
  – Closed hashing
  – Deleting

• The 2/3rds rule
Closed Hashing

1   23     32           44          End
2
3
4   33      Hash table is supplemented by
5           a linked list, which is used to
            store colliding entries.
6
7           Therefore, some values are
            found outside of the standard
            hash table (in the linked list)
‘Open’ Hashing

            Some strategy is used to fit
            colliding entries in a
            predictable way inside the
1   23
            existing table
2   32
3   44
            For this to work, the size of
4   33      the table needs to be
5           significantly bigger than the
            total number of records
6
7           At least 3:2
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

More Related Content

PPT
Hashing PPT
Saurabh Kumar
 
PPTX
Hashing in datastructure
rajshreemuthiah
 
PPTX
Hashing
kurubameena1
 
PPT
Hashing
amoldkul
 
PPTX
Hashing data
umair khan
 
PPT
Data Structure and Algorithms Hashing
ManishPrajapati78
 
PPT
Hashing
Ghaffar Khan
 
PPT
Hashing
debolina13
 
Hashing PPT
Saurabh Kumar
 
Hashing in datastructure
rajshreemuthiah
 
Hashing
kurubameena1
 
Hashing
amoldkul
 
Hashing data
umair khan
 
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Hashing
Ghaffar Khan
 
Hashing
debolina13
 

What's hot (20)

PPT
4.4 hashing
Krish_ver2
 
PPT
Concept of hashing
Rafi Dar
 
PPT
18 hashing
deonnash
 
ZIP
Hashing
Sri Prasanna
 
PDF
Hashing Algorithm
Hayi Nukman
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPT
Chapter 12 ds
Hanif Durad
 
PPTX
linear probing
rajshreemuthiah
 
PDF
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
 
PPTX
Hash table in data structure and algorithm
Aamir Sohail
 
PDF
Hashing
Ramzi Alqrainy
 
PPTX
Hashing algorithms and its uses
Jawad Khan
 
PPTX
Quadratic probing
rajshreemuthiah
 
PPTX
Hashing Techniques in Data Structures Part2
SHAKOOR AB
 
PDF
Application of hashing in better alg design tanmay
Tanmay 'Unsinkable'
 
PDF
Hashing and Hash Tables
adil raja
 
PDF
08 Hash Tables
Andres Mendez-Vazquez
 
PPTX
Hashing
Dinesh Vujuru
 
4.4 hashing
Krish_ver2
 
Concept of hashing
Rafi Dar
 
18 hashing
deonnash
 
Hashing
Sri Prasanna
 
Hashing Algorithm
Hayi Nukman
 
Hashing In Data Structure
Meghaj Mallick
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Chapter 12 ds
Hanif Durad
 
linear probing
rajshreemuthiah
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
 
Hash table in data structure and algorithm
Aamir Sohail
 
Hashing algorithms and its uses
Jawad Khan
 
Quadratic probing
rajshreemuthiah
 
Hashing Techniques in Data Structures Part2
SHAKOOR AB
 
Application of hashing in better alg design tanmay
Tanmay 'Unsinkable'
 
Hashing and Hash Tables
adil raja
 
08 Hash Tables
Andres Mendez-Vazquez
 
Hashing
Dinesh Vujuru
 
Ad

Viewers also liked (18)

PPTX
Hash tables
Chester Hartin
 
PPT
Ch17 Hashing
leminhvuong
 
PPTX
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
Hash Function
Siddharth Srivastava
 
PPT
Secure hashing algorithm
Karteek Paruchuri
 
PPT
Quick Sort
priyankanaidu6
 
PPT
358 33 powerpoint-slides_15-hashing-collision_chapter-15
sumitbardhan
 
PDF
Proper passwordhashing
fangjiafu
 
PDF
Message queues
Ahmad karawash
 
PDF
Password hashing, salting, bycrpt
Ahmad karawash
 
PPTX
Hashing 1
Shyam Khant
 
PPT
Smart antennas
Umesh Chalva
 
PDF
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
PyData
 
ODP
Security in the Real World - JavaOne 2013
MattKilner
 
PPT
Computer
Shivangi Shah
 
ODP
Disclosing password hashing policies
Michal Špaček
 
PPTX
Merging
ihdsinfo
 
PPTX
Intro to Hash tables
Amy Hua
 
Hash tables
Chester Hartin
 
Ch17 Hashing
leminhvuong
 
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Hash Function
Siddharth Srivastava
 
Secure hashing algorithm
Karteek Paruchuri
 
Quick Sort
priyankanaidu6
 
358 33 powerpoint-slides_15-hashing-collision_chapter-15
sumitbardhan
 
Proper passwordhashing
fangjiafu
 
Message queues
Ahmad karawash
 
Password hashing, salting, bycrpt
Ahmad karawash
 
Hashing 1
Shyam Khant
 
Smart antennas
Umesh Chalva
 
Probabilistic Data Structures and Approximate Solutions Oleksandr Pryymak
PyData
 
Security in the Real World - JavaOne 2013
MattKilner
 
Computer
Shivangi Shah
 
Disclosing password hashing policies
Michal Špaček
 
Merging
ihdsinfo
 
Intro to Hash tables
Amy Hua
 
Ad

Similar to Hashing (20)

PDF
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
 
PPTX
Data Structures-Topic-Hashing, Collision
sailaja156145
 
PPTX
hashing in data structures and its applications
manjeshbngowda
 
PPTX
hashing in data strutures advanced in languae java
ishasharma835109
 
PPTX
Lecture14_15_Hashing.pptx
SLekshmiNair
 
PPTX
Hash table
Vu Tran
 
PPTX
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
PPT
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
PPTX
Hashing and Collision Advanced data structure and algorithm
yogoso2948
 
PPTX
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
mohanrajm63
 
PPTX
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
PPTX
Hashing And Hashing Tables
Chinmaya M. N
 
PPTX
Hashing
invertis university
 
PDF
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
PPTX
hashing in data structure for Btech .pptx
soniasharmafdp
 
PPTX
hashing in data structure for engineering.pptx
soniasharmafdp
 
PDF
DataBaseManagementSystems-BTECH--UNIT-5.pdf
Uma Kakarlapudi
 
PPTX
hashing in data structure for Btech.pptx
soniasharmafdp
 
PPTX
Hashing
Amar Jukuntla
 
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
 
Data Structures-Topic-Hashing, Collision
sailaja156145
 
hashing in data structures and its applications
manjeshbngowda
 
hashing in data strutures advanced in languae java
ishasharma835109
 
Lecture14_15_Hashing.pptx
SLekshmiNair
 
Hash table
Vu Tran
 
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
Hashing and Collision Advanced data structure and algorithm
yogoso2948
 
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
mohanrajm63
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
Hashing And Hashing Tables
Chinmaya M. N
 
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
hashing in data structure for Btech .pptx
soniasharmafdp
 
hashing in data structure for engineering.pptx
soniasharmafdp
 
DataBaseManagementSystems-BTECH--UNIT-5.pdf
Uma Kakarlapudi
 
hashing in data structure for Btech.pptx
soniasharmafdp
 
Hashing
Amar Jukuntla
 

More from grahamwell (20)

PPTX
Pseudocode
grahamwell
 
PPT
Excel =if function
grahamwell
 
PPT
Excel Min max-average
grahamwell
 
PPTX
What is binary and why do we use it?
grahamwell
 
PPTX
Introduction to touch develop
grahamwell
 
PPTX
Introduction to touch develop
grahamwell
 
PPTX
The software story
grahamwell
 
PPTX
Turtle graphics
grahamwell
 
PPTX
Database field types
grahamwell
 
PPTX
Databases 101
grahamwell
 
PPTX
Kodu controls
grahamwell
 
PPT
Pascal names and types
grahamwell
 
PPT
Python part two names and types
grahamwell
 
PPTX
Abstraction - Year 9
grahamwell
 
PPTX
Thinking about your project
grahamwell
 
PPTX
The rail fence
grahamwell
 
PPT
Lesson 1
grahamwell
 
PPT
Rsa encryption
grahamwell
 
PPT
Server side scripts
grahamwell
 
PPTX
Revision topic 1 sensors and control
grahamwell
 
Pseudocode
grahamwell
 
Excel =if function
grahamwell
 
Excel Min max-average
grahamwell
 
What is binary and why do we use it?
grahamwell
 
Introduction to touch develop
grahamwell
 
Introduction to touch develop
grahamwell
 
The software story
grahamwell
 
Turtle graphics
grahamwell
 
Database field types
grahamwell
 
Databases 101
grahamwell
 
Kodu controls
grahamwell
 
Pascal names and types
grahamwell
 
Python part two names and types
grahamwell
 
Abstraction - Year 9
grahamwell
 
Thinking about your project
grahamwell
 
The rail fence
grahamwell
 
Lesson 1
grahamwell
 
Rsa encryption
grahamwell
 
Server side scripts
grahamwell
 
Revision topic 1 sensors and control
grahamwell
 

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 Hashing 1 23 32 44 End 2 3 4 33 Hash table is supplemented by 5 a linked list, which is used to store colliding entries. 6 7 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 the 1 23 existing table 2 32 3 44 For this to work, the size of 4 33 the table needs to be 5 significantly bigger than the total number of records 6 7 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