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
Data Structures : hashing (1)
Home
 
PPTX
Hash table
Vu Tran
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Sorting Algorithms
Pranay Neema
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
Hashing in datastructure
rajshreemuthiah
 
PDF
sparse matrix in data structure
MAHALAKSHMI P
 
PPTX
Sparse matrix and its representation data structure
Vardhil Patel
 
PPTX
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
PPT
Hashing PPT
Saurabh Kumar
 
PPT
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
PPTX
Linked List
Ashim Lamichhane
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
PPTX
Linear and Binary search
Nisha Soms
 
PDF
Java Linked List Tutorial | Edureka
Edureka!
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPTX
Abstract Data Types
karthikeyanC40
 
Data Structures : hashing (1)
Home
 
Hash table
Vu Tran
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Sorting Algorithms
Pranay Neema
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Hashing in datastructure
rajshreemuthiah
 
sparse matrix in data structure
MAHALAKSHMI P
 
Sparse matrix and its representation data structure
Vardhil Patel
 
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
Hashing PPT
Saurabh Kumar
 
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Linked List
Ashim Lamichhane
 
Hashing In Data Structure
Meghaj Mallick
 
Linear and Binary search
Nisha Soms
 
Java Linked List Tutorial | Edureka
Edureka!
 
Queue in Data Structure
Janki Shah
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Abstract Data Types
karthikeyanC40
 

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

PPT
358 33 powerpoint-slides_15-hashing-collision_chapter-15
sumitbardhan
 
PPT
Hashing and collision for database systems
janakiraman123
 
PPT
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
PPT
11_hashtable-1.ppt. Data structure algorithm
farhankhan89766
 
PPTX
Unit viii searching and hashing
Tribhuvan University
 
PDF
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
PPT
lecture10.ppt
ShaistaRiaz4
 
PPTX
Hashing.pptx
kratika64
 
PPTX
Hashing .pptx
ParagAhir1
 
PPTX
Presentation.pptx
AgonySingh
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPTX
Unit 6. Arrays
Ashim Lamichhane
 
PPTX
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
PDF
08 Hash Tables
Andres Mendez-Vazquez
 
PPTX
hashing in data strutures advanced in languae java
ishasharma835109
 
PPT
Hashing
Ghaffar Khan
 
PPT
Introduction to Hashing in Data Structure using C++
debasisdas225831
 
PPTX
Data Structures-Topic-Hashing, Collision
sailaja156145
 
PDF
Hashing CollisionDetection in Data Structures
LifnaCS1
 
PPT
Mesics lecture 8 arrays in 'c'
eShikshak
 
358 33 powerpoint-slides_15-hashing-collision_chapter-15
sumitbardhan
 
Hashing and collision for database systems
janakiraman123
 
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
11_hashtable-1.ppt. Data structure algorithm
farhankhan89766
 
Unit viii searching and hashing
Tribhuvan University
 
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
lecture10.ppt
ShaistaRiaz4
 
Hashing.pptx
kratika64
 
Hashing .pptx
ParagAhir1
 
Presentation.pptx
AgonySingh
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Unit 6. Arrays
Ashim Lamichhane
 
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
08 Hash Tables
Andres Mendez-Vazquez
 
hashing in data strutures advanced in languae java
ishasharma835109
 
Hashing
Ghaffar Khan
 
Introduction to Hashing in Data Structure using C++
debasisdas225831
 
Data Structures-Topic-Hashing, Collision
sailaja156145
 
Hashing CollisionDetection in Data Structures
LifnaCS1
 
Mesics lecture 8 arrays in 'c'
eShikshak
 
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)

PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 

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