SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Hashing 
Dictionary 
Direct-access Table 
Chaining 
Hash Function
Dictionary 
● Abstract Data type, maintain set of items with keys. 
– Insert (item) – also replacing existed item 
– Delete (item) 
– Search (key): return the item with given key or report if 
doesn't exist (null). 
Item → (key, value)
Simple Approach: DAT 
Storing items directly into 
giant array which is the 
index of item as key. 
0 NULL 
1 ITEM 1 
2 NULL 
3 NULL 
4 ITEM 2 
... 
... 
m-1 ...
Direct-access 
Binary search 
items[11] 
0 null 
1 null 
... ... 
7 7 
8 null 
9 9 
10 null 
11 11 
Direct access 
i→ 1 2 4 5 7 9 11 
Search for 11, low: 0, upper: 5, mid = 5/2 = 2 
| check for 11 
i→ 2 2 4 5 7 9 11 
Low = 3, upper = 5, mid = 4 
|check for 11 
i→ 3 2 4 5 7 9 11 
Low = 5, upper = 5, mid = 5 
Found 11 | 
i→ 4 2 4 5 7 9 11
Two Big Problem 
(1)Keys may be negative integers 
● Maps keys into non negative integers (such as String or 
string of bits) 
(2)Gigantic memory 
● Hashing (cut into piece)
Big idea 
Reduce universe () of all keys (integers) 
down to reasonable size of m for table. 0 NULL 
1 ITEM 1 
2 NULL 
3 NULL 
4 ITEM 2 
... 
... 
m-1 ... 
k1 
k2 
k3 
k4 
keyspace 
h(k2) = 1 
h(k3) = 4 
h(k) 
Ideal: m = (n)
Problem 
● There probably collision 
– i.e: 
h(kx) = h(kj) but kx ≠ kj 
0 NULL 
1 ITEM 1 
2 NULL 
3 NULL 
4 ITEM 2 
... 
... 
m-1 ... 
k1 
k2 
k3 
k4 
keyspace 
h(k1) = 4 
h(k4) = 4 
h(k)
Chaining 
● Use linked list to store value with collide keys. 
0 NULL / 
1 ITEM 1 / 
2 NULL / 
3 NULL / 
4 ITEM 2 ITEM 3 / 
... 
... / 
m-1 ... / 
k1 
k2 
k3 
k4 
keyspace 
h(k1) = 4 
h(k4) = 4 
h(k) Worst cases: 
- a bunch of keys is 
mapped into the same 
index
Length of chain 
Expected length of chain for n keys with m slots: 
n 
m 
=⍺ 
⍺ = load factor of table 
⍺ = O(1) if m = O(n)
Hash functions 
(1) Division Method: 
h(k )=k modm 
(2) Multiplication method 
h(k )=[(a . k )mod 2w ]≫(w−r ) 
a = integer 
w = bit of machine 
r = bits to shift 
m=2r
Cont... 
(3) Universal hashing 
h(k )=[(a . k+b)mod p ]modm 
Random integer 
∈ {0,1,..., p-1} 
Prime > || 
Worst cases: k1 ≠ k2 
Pr 
[h (k 1)=h (k 2)] 
= 
1 
m
Sample of code

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Hashing
HashingHashing
Hashing
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
18 hashing
18 hashing18 hashing
18 hashing
 
Hash table
Hash tableHash table
Hash table
 
Open addressiing &rehashing,extendiblevhashing
Open addressiing &rehashing,extendiblevhashingOpen addressiing &rehashing,extendiblevhashing
Open addressiing &rehashing,extendiblevhashing
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Application of hashing in better alg design tanmay
Application of hashing in better alg design tanmayApplication of hashing in better alg design tanmay
Application of hashing in better alg design tanmay
 
Hashing
HashingHashing
Hashing
 
Open Addressing on Hash Tables
Open Addressing on Hash Tables Open Addressing on Hash Tables
Open Addressing on Hash Tables
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Hashing data
Hashing dataHashing data
Hashing data
 
Hashing
HashingHashing
Hashing
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Hash tables
Hash tablesHash tables
Hash tables
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
Hashing
HashingHashing
Hashing
 

Similar a Hashing Algorithm

Similar a Hashing Algorithm (20)

Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
Lec5
Lec5Lec5
Lec5
 
Data structure lecture 4
Data structure lecture 4Data structure lecture 4
Data structure lecture 4
 
Lec5
Lec5Lec5
Lec5
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
03.01 hash tables
03.01 hash tables03.01 hash tables
03.01 hash tables
 
searching.pdf
searching.pdfsearching.pdf
searching.pdf
 
Algo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptAlgo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.ppt
 
13-hashing.ppt
13-hashing.ppt13-hashing.ppt
13-hashing.ppt
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptxBST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
BST+ RedBlackTrees CNN stands for Convolutional Neural Network.pptx
 
Lec4
Lec4Lec4
Lec4
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
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
 
Sorting
SortingSorting
Sorting
 
Lec34
Lec34Lec34
Lec34
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Array 2
Array 2Array 2
Array 2
 

Último

Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Hiroshi SHIBATA
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 

Último (20)

Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 

Hashing Algorithm

  • 1. Hashing Dictionary Direct-access Table Chaining Hash Function
  • 2. Dictionary ● Abstract Data type, maintain set of items with keys. – Insert (item) – also replacing existed item – Delete (item) – Search (key): return the item with given key or report if doesn't exist (null). Item → (key, value)
  • 3. Simple Approach: DAT Storing items directly into giant array which is the index of item as key. 0 NULL 1 ITEM 1 2 NULL 3 NULL 4 ITEM 2 ... ... m-1 ...
  • 4. Direct-access Binary search items[11] 0 null 1 null ... ... 7 7 8 null 9 9 10 null 11 11 Direct access i→ 1 2 4 5 7 9 11 Search for 11, low: 0, upper: 5, mid = 5/2 = 2 | check for 11 i→ 2 2 4 5 7 9 11 Low = 3, upper = 5, mid = 4 |check for 11 i→ 3 2 4 5 7 9 11 Low = 5, upper = 5, mid = 5 Found 11 | i→ 4 2 4 5 7 9 11
  • 5. Two Big Problem (1)Keys may be negative integers ● Maps keys into non negative integers (such as String or string of bits) (2)Gigantic memory ● Hashing (cut into piece)
  • 6. Big idea Reduce universe () of all keys (integers) down to reasonable size of m for table. 0 NULL 1 ITEM 1 2 NULL 3 NULL 4 ITEM 2 ... ... m-1 ... k1 k2 k3 k4 keyspace h(k2) = 1 h(k3) = 4 h(k) Ideal: m = (n)
  • 7. Problem ● There probably collision – i.e: h(kx) = h(kj) but kx ≠ kj 0 NULL 1 ITEM 1 2 NULL 3 NULL 4 ITEM 2 ... ... m-1 ... k1 k2 k3 k4 keyspace h(k1) = 4 h(k4) = 4 h(k)
  • 8. Chaining ● Use linked list to store value with collide keys. 0 NULL / 1 ITEM 1 / 2 NULL / 3 NULL / 4 ITEM 2 ITEM 3 / ... ... / m-1 ... / k1 k2 k3 k4 keyspace h(k1) = 4 h(k4) = 4 h(k) Worst cases: - a bunch of keys is mapped into the same index
  • 9. Length of chain Expected length of chain for n keys with m slots: n m =⍺ ⍺ = load factor of table ⍺ = O(1) if m = O(n)
  • 10. Hash functions (1) Division Method: h(k )=k modm (2) Multiplication method h(k )=[(a . k )mod 2w ]≫(w−r ) a = integer w = bit of machine r = bits to shift m=2r
  • 11. Cont... (3) Universal hashing h(k )=[(a . k+b)mod p ]modm Random integer ∈ {0,1,..., p-1} Prime > || Worst cases: k1 ≠ k2 Pr [h (k 1)=h (k 2)] = 1 m