SlideShare a Scribd company logo
1 of 10
Hashing and Collision
Introduction :
• Linear Search takes O(n) and binary search takes O(log n)
• Search operation to be performed in time proportion O(1)
2 solutions:
1st Solution :
• Wastage of storage space :
• Therefore store ID with last 2 digit and in same index
2nd solution:
Using hash table
Using hash function
Hash Tables :
• Is a data structure
• Keys are mapped to array positions
• Value stored in hash table can be found in O(1)
Ex:
Hash function h is used to calculate the index
at which the element with key k will be
stored
The process of mapping keys to appropriate
locations in hash table is called hashing
Each key from set K is mapped to
locations generated by hash
function
K2 and k6 point to same memory
location
K5 and k7 same
Known as collision – 2/more keys
map to the same memory location
Hash Functions :
• Is a mathematical formula, when applied to a key, produces an integer which
can be used as an index for the key in hash table
• 4 functions:
1) Division Method
2) Multiplication method
3) Mid-Square method
4) Folding method
• Uses numeric keys
• If alphanumeric – ASCII value can be used for transformation
1) Division Method :
• Simple method
• Works very fast
• Care – to select suitable value for M (prefer prime number)
• X is an integer
• Divides x by m, and then uses the remainder obtained
• Hash function – h(x) = X Mod M
• Ex:
• Ex :
Data(X) = 36, 18, 72, 43, 6
N= table size / slot
2) Multiplication Method :
• Steps:
1) Choose A – 0<A<1
2) Multiply key K by A
3) Extract functional part kA
4) Multiply result of step3 by size of hash table
Ex:
3) Mid Square Method :
• Works in 2 steps:
1) Square the value of the k^2
2) Extract the middle r digits of the result
• All digits of the key value contribute to result
• Result is not dominated(k) = s

More Related Content

Similar to PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx

Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptx
my6305874
 
Design data Analysis hashing.ppt by piyush
Design  data Analysis hashing.ppt by piyushDesign  data Analysis hashing.ppt by piyush
Design data Analysis hashing.ppt by piyush
22001003058
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
Sajid Marwat
 

Similar to PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx (20)

Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptx
 
Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptx
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Hashing
HashingHashing
Hashing
 
HASHING.ppt.pptx
HASHING.ppt.pptxHASHING.ppt.pptx
HASHING.ppt.pptx
 
Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
Design data Analysis hashing.ppt by piyush
Design  data Analysis hashing.ppt by piyushDesign  data Analysis hashing.ppt by piyush
Design data Analysis hashing.ppt by piyush
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Lec5
Lec5Lec5
Lec5
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
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
 
Lec5
Lec5Lec5
Lec5
 
Hash tables
Hash tablesHash tables
Hash tables
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
Hashing 1
Hashing 1Hashing 1
Hashing 1
 
Data Structures- Hashing
Data Structures- Hashing Data Structures- Hashing
Data Structures- Hashing
 

Recently uploaded

Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get CytotecAbortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
yulianti213969
 
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
zifhagzkk
 
Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...
Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...
Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...
mikehavy0
 
如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样
如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样
如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样
wsppdmt
 
Huawei Ransomware Protection Storage Solution Technical Overview Presentation...
Huawei Ransomware Protection Storage Solution Technical Overview Presentation...Huawei Ransomware Protection Storage Solution Technical Overview Presentation...
Huawei Ransomware Protection Storage Solution Technical Overview Presentation...
LuisMiguelPaz5
 
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Bertram Ludäscher
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
acoha1
 

Recently uploaded (20)

Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get CytotecAbortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
 
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
obat aborsi Tarakan wa 081336238223 jual obat aborsi cytotec asli di Tarakan9...
 
Predictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesPredictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting Techniques
 
DAA Assignment Solution.pdf is the best1
DAA Assignment Solution.pdf is the best1DAA Assignment Solution.pdf is the best1
DAA Assignment Solution.pdf is the best1
 
Harnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptxHarnessing the Power of GenAI for BI and Reporting.pptx
Harnessing the Power of GenAI for BI and Reporting.pptx
 
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
如何办理(Dalhousie毕业证书)达尔豪斯大学毕业证成绩单留信学历认证
 
Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...
Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...
Abortion Clinic in Kempton Park +27791653574 WhatsApp Abortion Clinic Service...
 
如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样
如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样
如何办理澳洲拉筹伯大学毕业证(LaTrobe毕业证书)成绩单原件一模一样
 
Huawei Ransomware Protection Storage Solution Technical Overview Presentation...
Huawei Ransomware Protection Storage Solution Technical Overview Presentation...Huawei Ransomware Protection Storage Solution Technical Overview Presentation...
Huawei Ransomware Protection Storage Solution Technical Overview Presentation...
 
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...Reconciling Conflicting Data Curation Actions:  Transparency Through Argument...
Reconciling Conflicting Data Curation Actions: Transparency Through Argument...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Bios of leading Astrologers & Researchers
Bios of leading Astrologers & ResearchersBios of leading Astrologers & Researchers
Bios of leading Astrologers & Researchers
 
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
 
Seven tools of quality control.slideshare
Seven tools of quality control.slideshareSeven tools of quality control.slideshare
Seven tools of quality control.slideshare
 
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(UPenn毕业证书)宾夕法尼亚大学毕业证成绩单本科硕士学位证留信学历认证
 
Pentesting_AI and security challenges of AI
Pentesting_AI and security challenges of AIPentesting_AI and security challenges of AI
Pentesting_AI and security challenges of AI
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptx
 

PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx

  • 2. Introduction : • Linear Search takes O(n) and binary search takes O(log n) • Search operation to be performed in time proportion O(1) 2 solutions: 1st Solution :
  • 3. • Wastage of storage space : • Therefore store ID with last 2 digit and in same index 2nd solution: Using hash table Using hash function
  • 4. Hash Tables : • Is a data structure • Keys are mapped to array positions • Value stored in hash table can be found in O(1) Ex: Hash function h is used to calculate the index at which the element with key k will be stored The process of mapping keys to appropriate locations in hash table is called hashing
  • 5. Each key from set K is mapped to locations generated by hash function K2 and k6 point to same memory location K5 and k7 same Known as collision – 2/more keys map to the same memory location
  • 6. Hash Functions : • Is a mathematical formula, when applied to a key, produces an integer which can be used as an index for the key in hash table • 4 functions: 1) Division Method 2) Multiplication method 3) Mid-Square method 4) Folding method • Uses numeric keys • If alphanumeric – ASCII value can be used for transformation
  • 7. 1) Division Method : • Simple method • Works very fast • Care – to select suitable value for M (prefer prime number) • X is an integer • Divides x by m, and then uses the remainder obtained • Hash function – h(x) = X Mod M
  • 8. • Ex: • Ex : Data(X) = 36, 18, 72, 43, 6 N= table size / slot
  • 9. 2) Multiplication Method : • Steps: 1) Choose A – 0<A<1 2) Multiply key K by A 3) Extract functional part kA 4) Multiply result of step3 by size of hash table Ex:
  • 10. 3) Mid Square Method : • Works in 2 steps: 1) Square the value of the k^2 2) Extract the middle r digits of the result • All digits of the key value contribute to result • Result is not dominated(k) = s