SlideShare a Scribd company logo
8
Most read
10
Most read
11
Most read
Hash Table
Presenting to: Prof M.Arshad
Class: Analysis of Algorithms
Department of Computer Science
Searching
Link List
Array
Trees etc
Aamir sohail 2
Searching: Time Complexity
Link List
O(n)
Array (unsorted)
O(n)
Aamir sohail 3
Searching: Time Complexity
Array (Sorted)
O(log2 n)
Binary Search tree
O(log2 n)
Aamir sohail 4
Searching: Time Complexity
Hash Table
O(1)
Aamir sohail 5
Example 1
• To store the key/values pair, we can use
simple array like data structure where
keys can be used as index to store
values.
Aamir sohail 6
Example 2
• We have 10 complaints indexed with a number
ranges from 0 to 9 ( say complaint number)
• We have an array of 10 spaces to store 10
complaints
• Here we can use complaint number as key and
it is nothing but index number in an array.
Aamir sohail 7
Example 3
• We have 5 students to store in table (nothing
but a custom array). Student will be assigned
a Roll no, so roll no is the key value to identify
a student.
• Assume that the table (array) has 10 slots
available.
• Also assume that a roll no is a 4 digit number
Aamir sohail 8
Terms
• Hash Table
- Mostly it is an array to store dataset.
• Hash Function
- a hash function is any function that can be
used to map dataset.
• Hashing
- in hashing large keys are converted in to
small ones by using hash function and then the
values are stored in hash table.
Aamir sohail 9
Hash Functions
• A hash function usually means a function
that compresses. Meaning the output is
shorter than the input.
• A hash function is any function that can
be used to map data of arbitrary size to
data of fixed size.
Aamir sohail 10
Parameters of good hash function
• Easy to Compute
• Minimize Collision
Aamir sohail 11
Perfect Hashing
• Perfect hashing maps each valid input to
a different hash value ( No Collision )
Aamir sohail 12
Hash function example
int hash(int x)
{
return(x%10);
}
Aamir sohail 13
Hash Function
• A good hash function to use with
integer key values is the mid-square
method
• The mid-square method squares the key
value, and then takes out the middle r
bits of the result.
Aamir sohail 14
Collision
• A situation when the resultant hashes
for two or more data elements in data
set, maps to the same location in the
table, is called a hash collision.
• In such situation two or more data
elements would qualify to be
stored/mapped to the same location in
hash table.
Aamir sohail 15
Solution for Hash Collision
• Two types of solutions for hash collision
- Open Hashing (chaining)
- Closed Hashing (open Addressing)
• The difference between the two has to do
with
- whether collisions are stored outside the
table (open hashing), or
- whether collisions result in storing one
of the records at another slot in the table
(closed hashing).
Aamir sohail 16
Open Hashing
• The simplest form of open hashing
defines each slot in the hash table to be
the head of linked list.
• All records that hash to a particular
slot are placed on that slot’s linked list.
Aamir sohail 17
Closed Hashing
• Linear Probing
• Quadratic Probing
• Double Hashing
Aamir sohail 18
Any Question about the
Hashing
Hash Function &
Hash table?
Aamir sohail 19
References
Introduction to Algorithms (Second
Edition)
- by: Thomas H.Cormen
Basics of Data Structure
Video Lectures
Aamir sohail 20

More Related Content

What's hot (20)

PPTX
Hashing in datastructure
rajshreemuthiah
 
PPTX
Linked list in Data Structure and Algorithm
KristinaBorooah
 
PPTX
Sparse matrix
dincyjain
 
PPTX
Linked List
Ashim Lamichhane
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
Sparse matrix and its representation data structure
Vardhil Patel
 
PDF
sparse matrix in data structure
MAHALAKSHMI P
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
PPTX
Searching
Ashim Lamichhane
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
Asymptotic Notation
Protap Mondal
 
PPTX
linked list in data structure
shameen khan
 
PPTX
Hash table
Vu Tran
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
Array
HarshKumar943076
 
PPT
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
DOC
Time and space complexity
Ankit Katiyar
 
Hashing in datastructure
rajshreemuthiah
 
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Sparse matrix
dincyjain
 
Linked List
Ashim Lamichhane
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Sparse matrix and its representation data structure
Vardhil Patel
 
sparse matrix in data structure
MAHALAKSHMI P
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Hashing In Data Structure
Meghaj Mallick
 
Searching
Ashim Lamichhane
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Asymptotic Notation
Protap Mondal
 
linked list in data structure
shameen khan
 
Hash table
Vu Tran
 
Linked list
KalaivaniKS1
 
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
Time and space complexity
Ankit Katiyar
 

Similar to Hash table in data structure and algorithm (20)

PPT
Chapter 12 ds
Hanif Durad
 
PPTX
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
PPT
11_hashtable-1.ppt. Data structure algorithm
farhankhan89766
 
PDF
Hash pre
Waed Shagareen
 
PPTX
hashing in data strutures advanced in languae java
ishasharma835109
 
PDF
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
 
PPTX
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
 
PPTX
Data Structures and Agorithm: DS 24 Hash Tables.pptx
RashidFaridChishti
 
PPTX
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
PPT
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
PPTX
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
PPTX
Hash in datastructures by using the c language.pptx
my6305874
 
PPTX
Unit viii searching and hashing
Tribhuvan University
 
PDF
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
PDF
L21_Hashing.pdf
BlessingMapadza1
 
PPT
Hash presentation
omercode
 
PPTX
asdfew.pptx
hunterkurosaki
 
PPTX
Presentation.pptx
AgonySingh
 
PDF
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
PPT
Analysis Of Algorithms - Hashing
Sam Light
 
Chapter 12 ds
Hanif Durad
 
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
11_hashtable-1.ppt. Data structure algorithm
farhankhan89766
 
Hash pre
Waed Shagareen
 
hashing in data strutures advanced in languae java
ishasharma835109
 
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
 
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
 
Data Structures and Agorithm: DS 24 Hash Tables.pptx
RashidFaridChishti
 
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
Hash in datastructures by using the c language.pptx
my6305874
 
Unit viii searching and hashing
Tribhuvan University
 
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
L21_Hashing.pdf
BlessingMapadza1
 
Hash presentation
omercode
 
asdfew.pptx
hunterkurosaki
 
Presentation.pptx
AgonySingh
 
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
Analysis Of Algorithms - Hashing
Sam Light
 
Ad

More from Aamir Sohail (7)

PPT
Presentation on java servlets
Aamir Sohail
 
PPT
Presentation on html, css
Aamir Sohail
 
PPTX
Line clipping algorithm (Detailed)
Aamir Sohail
 
PPT
Vb script
Aamir Sohail
 
PPTX
Infromation securiity
Aamir Sohail
 
PPTX
Network Security Policies
Aamir Sohail
 
PPTX
Scheduling and scheduling personnel
Aamir Sohail
 
Presentation on java servlets
Aamir Sohail
 
Presentation on html, css
Aamir Sohail
 
Line clipping algorithm (Detailed)
Aamir Sohail
 
Vb script
Aamir Sohail
 
Infromation securiity
Aamir Sohail
 
Network Security Policies
Aamir Sohail
 
Scheduling and scheduling personnel
Aamir Sohail
 
Ad

Recently uploaded (20)

PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
community health nursing question paper 2.pdf
Prince kumar
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 

Hash table in data structure and algorithm

  • 1. Hash Table Presenting to: Prof M.Arshad Class: Analysis of Algorithms Department of Computer Science
  • 3. Searching: Time Complexity Link List O(n) Array (unsorted) O(n) Aamir sohail 3
  • 4. Searching: Time Complexity Array (Sorted) O(log2 n) Binary Search tree O(log2 n) Aamir sohail 4
  • 5. Searching: Time Complexity Hash Table O(1) Aamir sohail 5
  • 6. Example 1 • To store the key/values pair, we can use simple array like data structure where keys can be used as index to store values. Aamir sohail 6
  • 7. Example 2 • We have 10 complaints indexed with a number ranges from 0 to 9 ( say complaint number) • We have an array of 10 spaces to store 10 complaints • Here we can use complaint number as key and it is nothing but index number in an array. Aamir sohail 7
  • 8. Example 3 • We have 5 students to store in table (nothing but a custom array). Student will be assigned a Roll no, so roll no is the key value to identify a student. • Assume that the table (array) has 10 slots available. • Also assume that a roll no is a 4 digit number Aamir sohail 8
  • 9. Terms • Hash Table - Mostly it is an array to store dataset. • Hash Function - a hash function is any function that can be used to map dataset. • Hashing - in hashing large keys are converted in to small ones by using hash function and then the values are stored in hash table. Aamir sohail 9
  • 10. Hash Functions • A hash function usually means a function that compresses. Meaning the output is shorter than the input. • A hash function is any function that can be used to map data of arbitrary size to data of fixed size. Aamir sohail 10
  • 11. Parameters of good hash function • Easy to Compute • Minimize Collision Aamir sohail 11
  • 12. Perfect Hashing • Perfect hashing maps each valid input to a different hash value ( No Collision ) Aamir sohail 12
  • 13. Hash function example int hash(int x) { return(x%10); } Aamir sohail 13
  • 14. Hash Function • A good hash function to use with integer key values is the mid-square method • The mid-square method squares the key value, and then takes out the middle r bits of the result. Aamir sohail 14
  • 15. Collision • A situation when the resultant hashes for two or more data elements in data set, maps to the same location in the table, is called a hash collision. • In such situation two or more data elements would qualify to be stored/mapped to the same location in hash table. Aamir sohail 15
  • 16. Solution for Hash Collision • Two types of solutions for hash collision - Open Hashing (chaining) - Closed Hashing (open Addressing) • The difference between the two has to do with - whether collisions are stored outside the table (open hashing), or - whether collisions result in storing one of the records at another slot in the table (closed hashing). Aamir sohail 16
  • 17. Open Hashing • The simplest form of open hashing defines each slot in the hash table to be the head of linked list. • All records that hash to a particular slot are placed on that slot’s linked list. Aamir sohail 17
  • 18. Closed Hashing • Linear Probing • Quadratic Probing • Double Hashing Aamir sohail 18
  • 19. Any Question about the Hashing Hash Function & Hash table? Aamir sohail 19
  • 20. References Introduction to Algorithms (Second Edition) - by: Thomas H.Cormen Basics of Data Structure Video Lectures Aamir sohail 20