SlideShare a Scribd company logo
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
Most read
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
Most read
11
Parameters of good hash function
• Easy to Compute
• Minimize Collision
Aamir sohail 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)

Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
Dr Sandeep Kumar Poonia
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
karthikeyanC40
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Stack
StackStack
Stack
Seema Sharma
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
sumitbardhan
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
Heaps
HeapsHeaps
Heaps
Hafiz Atif Amin
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
sumitbardhan
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 

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

Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptxLec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
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
farhankhan89766
 
Hash pre
Hash preHash pre
Hash pre
Waed Shagareen
 
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae javahashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
 
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdfhashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
 
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
unit-1-data structure and algorithms-hashing-2024-1 (1).pptxunit-1-data structure and algorithms-hashing-2024-1 (1).pptx
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
 
Data Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 24 Hash Tables.pptxData Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 24 Hash Tables.pptx
RashidFaridChishti
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
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
ssuserec8a711
 
Hashing Techniques in Data Strucures and Algorithm
Hashing Techniques in Data Strucures and AlgorithmHashing Techniques in Data Strucures and Algorithm
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
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
BabaShaikh3
 
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
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
Tribhuvan University
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
BlessingMapadza1
 
Hashing
HashingHashing
Hashing
Dawood Faheem Abbasi
 
Hash presentation
Hash presentationHash presentation
Hash presentation
omercode
 
asdfew.pptx
asdfew.pptxasdfew.pptx
asdfew.pptx
hunterkurosaki
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
AgonySingh
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptxLec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
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
farhankhan89766
 
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae javahashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
 
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdfhashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
hashtableeeeeeeeeeeeeeeeeeeeeeeeeeee.pdf
timoemin50
 
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
unit-1-data structure and algorithms-hashing-2024-1 (1).pptxunit-1-data structure and algorithms-hashing-2024-1 (1).pptx
unit-1-data structure and algorithms-hashing-2024-1 (1).pptx
pritimalkhede
 
Data Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 24 Hash Tables.pptxData Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 24 Hash Tables.pptx
RashidFaridChishti
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
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
ssuserec8a711
 
Hashing Techniques in Data Strucures and Algorithm
Hashing Techniques in Data Strucures and AlgorithmHashing Techniques in Data Strucures and Algorithm
Hashing Techniques in Data Strucures and Algorithm
BipinNaik9
 
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
BabaShaikh3
 
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
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
Hash presentation
Hash presentationHash presentation
Hash presentation
omercode
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
AgonySingh
 
Ad

More from Aamir Sohail (7)

Presentation on java servlets
Presentation on java servletsPresentation on java servlets
Presentation on java servlets
Aamir Sohail
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
Aamir Sohail
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)
Aamir Sohail
 
Vb script
Vb scriptVb script
Vb script
Aamir Sohail
 
Infromation securiity
Infromation securiityInfromation securiity
Infromation securiity
Aamir Sohail
 
Network Security Policies
Network Security PoliciesNetwork Security Policies
Network Security Policies
Aamir Sohail
 
Scheduling and scheduling personnel
Scheduling and scheduling personnelScheduling and scheduling personnel
Scheduling and scheduling personnel
Aamir Sohail
 
Presentation on java servlets
Presentation on java servletsPresentation on java servlets
Presentation on java servlets
Aamir Sohail
 
Presentation on html, css
Presentation on html, cssPresentation on html, css
Presentation on html, css
Aamir Sohail
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)
Aamir Sohail
 
Infromation securiity
Infromation securiityInfromation securiity
Infromation securiity
Aamir Sohail
 
Network Security Policies
Network Security PoliciesNetwork Security Policies
Network Security Policies
Aamir Sohail
 
Scheduling and scheduling personnel
Scheduling and scheduling personnelScheduling and scheduling personnel
Scheduling and scheduling personnel
Aamir Sohail
 
Ad

Recently uploaded (20)

Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 

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