SlideShare uma empresa Scribd logo
1 de 8
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

Mais conteúdo relacionado

Mais procurados

Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...NaveenPeter8
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its usesJawad Khan
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithmAamir Sohail
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxShreyasLawand
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)Home
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 

Mais procurados (20)

Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
 
Hashing data
Hashing dataHashing data
Hashing data
 
Hashing
HashingHashing
Hashing
 
Searching
SearchingSearching
Searching
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Binary search
Binary searchBinary search
Binary search
 
Hashing
HashingHashing
Hashing
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
linear probing
linear probinglinear probing
linear probing
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 

Destaque

Armed Conflict vs. Sustainable Development
Armed Conflict vs. Sustainable DevelopmentArmed Conflict vs. Sustainable Development
Armed Conflict vs. Sustainable DevelopmentAliasghar Abbasi
 
Introduction by Rogier Ormeling about the collection of Henk and Leonie Pij...
Introduction by  Rogier Ormeling  about the collection of Henk and Leonie Pij...Introduction by  Rogier Ormeling  about the collection of Henk and Leonie Pij...
Introduction by Rogier Ormeling about the collection of Henk and Leonie Pij...Henk Pijnenburg
 
Introduction to parallel computing chapter 2
Introduction to parallel computing chapter 2Introduction to parallel computing chapter 2
Introduction to parallel computing chapter 2Mahdi Eshraghi MHE
 
امضای همراه
امضای همراهامضای همراه
امضای همراهEsmaeil Abedi
 
SQL Injection; Attack & Prevention
SQL Injection; Attack & PreventionSQL Injection; Attack & Prevention
SQL Injection; Attack & PreventionMahdi Eshraghi MHE
 
ACC 201 Ch 10 Questions
ACC 201 Ch 10 QuestionsACC 201 Ch 10 Questions
ACC 201 Ch 10 QuestionsJohn Cusato
 
انواع مقالات علمی و تخصصی
انواع مقالات علمی و تخصصیانواع مقالات علمی و تخصصی
انواع مقالات علمی و تخصصیHavar Bathaee
 
Data Base Security (SQL Injection Attacks)
Data Base Security (SQL Injection Attacks)Data Base Security (SQL Injection Attacks)
Data Base Security (SQL Injection Attacks)Hassan Kooshkaki
 
Social networking sites_business_sop_18
Social networking sites_business_sop_18Social networking sites_business_sop_18
Social networking sites_business_sop_18Anas Vj
 
نوآوری باز در تحقیق و توسعه
نوآوری باز در تحقیق و توسعهنوآوری باز در تحقیق و توسعه
نوآوری باز در تحقیق و توسعهEsmaeil Abedi
 
Pki Digital Signature
Pki Digital SignaturePki Digital Signature
Pki Digital SignatureSaeed Aminian
 

Destaque (20)

عصر ارتباطات و دلواژسان
عصر ارتباطات و دلواژسانعصر ارتباطات و دلواژسان
عصر ارتباطات و دلواژسان
 
بروشور معرفی مرکز دولتی صدور گواهی الکترونیکی ریشه
بروشور معرفی مرکز دولتی صدور گواهی الکترونیکی ریشهبروشور معرفی مرکز دولتی صدور گواهی الکترونیکی ریشه
بروشور معرفی مرکز دولتی صدور گواهی الکترونیکی ریشه
 
Armed Conflict vs. Sustainable Development
Armed Conflict vs. Sustainable DevelopmentArmed Conflict vs. Sustainable Development
Armed Conflict vs. Sustainable Development
 
Introduction by Rogier Ormeling about the collection of Henk and Leonie Pij...
Introduction by  Rogier Ormeling  about the collection of Henk and Leonie Pij...Introduction by  Rogier Ormeling  about the collection of Henk and Leonie Pij...
Introduction by Rogier Ormeling about the collection of Henk and Leonie Pij...
 
Go Programming Language
Go Programming LanguageGo Programming Language
Go Programming Language
 
Blind justice
Blind justiceBlind justice
Blind justice
 
معرفی مرکز دولتی صدور گواهی الکترونیکی ریشه
معرفی مرکز دولتی صدور گواهی الکترونیکی ریشهمعرفی مرکز دولتی صدور گواهی الکترونیکی ریشه
معرفی مرکز دولتی صدور گواهی الکترونیکی ریشه
 
Introduction to parallel computing chapter 2
Introduction to parallel computing chapter 2Introduction to parallel computing chapter 2
Introduction to parallel computing chapter 2
 
امضای همراه
امضای همراهامضای همراه
امضای همراه
 
SQL Injection; Attack & Prevention
SQL Injection; Attack & PreventionSQL Injection; Attack & Prevention
SQL Injection; Attack & Prevention
 
زیرساخت کلید عمومی (PKI)، مفاهیم، کاربردها و کاربری امضای دیجیتال
زیرساخت کلید عمومی (PKI)، مفاهیم، کاربردها و کاربری امضای دیجیتالزیرساخت کلید عمومی (PKI)، مفاهیم، کاربردها و کاربری امضای دیجیتال
زیرساخت کلید عمومی (PKI)، مفاهیم، کاربردها و کاربری امضای دیجیتال
 
اصالت‌سنجی اسناد الکترونیکی (راهکار جلوگیری از جعل اسناد الکترونیکی)
اصالت‌سنجی اسناد الکترونیکی (راهکار جلوگیری از جعل اسناد الکترونیکی)اصالت‌سنجی اسناد الکترونیکی (راهکار جلوگیری از جعل اسناد الکترونیکی)
اصالت‌سنجی اسناد الکترونیکی (راهکار جلوگیری از جعل اسناد الکترونیکی)
 
ACC 201 Ch 10 Questions
ACC 201 Ch 10 QuestionsACC 201 Ch 10 Questions
ACC 201 Ch 10 Questions
 
آشنایی با زیرساخت کلید عمومی (PKI)
آشنایی با زیرساخت کلید عمومی (PKI)آشنایی با زیرساخت کلید عمومی (PKI)
آشنایی با زیرساخت کلید عمومی (PKI)
 
انواع مقالات علمی و تخصصی
انواع مقالات علمی و تخصصیانواع مقالات علمی و تخصصی
انواع مقالات علمی و تخصصی
 
Data Base Security (SQL Injection Attacks)
Data Base Security (SQL Injection Attacks)Data Base Security (SQL Injection Attacks)
Data Base Security (SQL Injection Attacks)
 
Social networking sites_business_sop_18
Social networking sites_business_sop_18Social networking sites_business_sop_18
Social networking sites_business_sop_18
 
نوآوری باز در تحقیق و توسعه
نوآوری باز در تحقیق و توسعهنوآوری باز در تحقیق و توسعه
نوآوری باز در تحقیق و توسعه
 
Pki Digital Signature
Pki Digital SignaturePki Digital Signature
Pki Digital Signature
 
Bioimpedance
BioimpedanceBioimpedance
Bioimpedance
 

Semelhante a Hashing

Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxSLekshmiNair
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesssuserec8a711
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashingRafi Dar
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxBabaShaikh3
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing TablesChinmaya M. N
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithmfarhankhan89766
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashingAkhil Prem
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
HASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptxHASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptxJITTAYASHWANTHREDDY
 
Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT icajiwol341
 

Semelhante a Hashing (20)

Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptx
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 
Hashing
HashingHashing
Hashing
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
 
Hashing
HashingHashing
Hashing
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
asdfew.pptx
asdfew.pptxasdfew.pptx
asdfew.pptx
 
HASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptxHASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptx
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 

Mais de grahamwell

Excel =if function
Excel =if functionExcel =if function
Excel =if functiongrahamwell
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average grahamwell
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?grahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch developgrahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch developgrahamwell
 
The software story
The software storyThe software story
The software storygrahamwell
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphicsgrahamwell
 
Database field types
Database field typesDatabase field types
Database field typesgrahamwell
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and typesgrahamwell
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and typesgrahamwell
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9grahamwell
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your projectgrahamwell
 
The rail fence
The rail fenceThe rail fence
The rail fencegrahamwell
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryptiongrahamwell
 
Server side scripts
Server side scriptsServer side scripts
Server side scriptsgrahamwell
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and controlgrahamwell
 

Mais de grahamwell (20)

Pseudocode
PseudocodePseudocode
Pseudocode
 
Excel =if function
Excel =if functionExcel =if function
Excel =if function
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
The software story
The software storyThe software story
The software story
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
 
Database field types
Database field typesDatabase field types
Database field types
 
Databases 101
Databases 101Databases 101
Databases 101
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and types
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your project
 
The rail fence
The rail fenceThe rail fence
The rail fence
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryption
 
Server side scripts
Server side scriptsServer side scripts
Server side scripts
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and control
 

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