SlideShare a Scribd company logo
Hashing Introduction
Hash Functions
Hash Table
Closed hashing(open addressing)
Linear Probing
Quadratic Probing
Double hashing
Open hashing(separate chaining)
Hashing
 The search time of each algorithm discussed so far
depends on number n depends on the number n of
items in the collection S of data.
A searching Technique, called Hashing or Hash
addressing, which is independent of number n.
We assume that
1. there is a file F of n records with a set K of keys which
unlikely determine the record in F.
2. F is maintained in memory by a Table T of m memory
locations and L is the set of memory addresses of
locations in T.
3. For notational convenience, the keys in K and
Address L are Integers.
Example
Suppose A company with 250 employees assign a 5-
digit employee number to each employee which is
used as primary key in company’s employee file.
We can use employee number as a address of record in
memory.
The search will require no comparisons at all.
Unfortunately, this technique will require space for
1,00,000 memory locations, where as fewer locations
would actually used.
So, this trade off for time is not worth the expense.
Hashing
 The general idea of using the key to determine the
address of record is an excellent idea, but it must be
modified so that great deal of space is not wasted.
This modification takes the form of a function H from
the set K of keys in to set L of memory address.
 H: K L , Is called a Hash Function or
 Unfortunately, Such a function H may not yield distinct
values: it is possible that two different keys k1 and k2 will
yield the same hash address. This situation is called Collision,
and some method must be used to resolve it.
Hash Functions
 the two principal criteria used in selecting a hash
function H: K L are as follows:
1. The function H should be very easy and quick to
compute.
2.The function H should as far as possible,
uniformly distribute the hash address through out
the set L so that there are minimum number of
collision.
Hash Functions
1. Division method: choose a number m larger than the number n of keys
in K. (m is usually either a prime number or a number without
small divisor) the hash function H is defined by
H(k) = k (mod m) or H(k) = k (mod m) + 1.
here k (mod m) denotes the reminder when k is divided by m. the
second formula is used when we want a hash address to range from
1 to m rather than 0 to m-1.
2. Midsquare method: the key k is squared. Then the hash function H is
defined by H(k) = l. where l is obtained by deleting digits from
both end of k^2.
3. Folding Method: the key k is portioned into a number of parts, k1, k2,
……,kr, where each part is added togather, ignoring the last carry.
H(k) = k1+k2+ ……………+Kr.
Sometimes, for extra “milling”, the even numbered parts, k2, k4, …. Are
each reversed befor addition.
Example of Hash Functions
 consider a company with 68 employees assigns a 4-digit employee
number to each employee. Suppose L consists of 100 two-digit
address: 00, 01, 02 , ……….99. we apply above hash functions to each of
following employee numbers: 3205, 7148,2345.
1. Division Method:
choose a prime number m close to 99, m=97.
H(k)=k(mod m): H(3205)=4, H(7148)=67, H(2345)=17.
2. Midsquare Method:
k= 3205 7148 2345
k^2= 10272025 51093904 5499025
H(k)= 72 93 99
3. Folding Method: chopping the key k into two parts and adding yield
the following hash address:
H(3205)=32+05=37, H(7148)=71+48=19, H(2345)=23+45=68
Or,
H(3205)=32+50=82, H(7148)=71+84=55, H(2345)=23+54=77
Collision Resolution
Suppose we want to add a new record R with key K to our file F, but
suppose the memory location address H(k) is already occupied. This
situation is called Collision.
There are two general ways to resolve collisions :
 Open addressing,(array method)
 Separate Chaining (linked list method)
The particular procedure that one choose depends on many factors.
One important factor is load factor (λ=n/m)i.e. ratio of number n of
keys in K (number of records in F) to m of hash address in L.
e.g. suppose a student class has 24 students and table has space for 365
records.
The efficiency of hash function with a collision resolution procedure is
measured by the average number of probes (key comparison) needed
to find the location of record with a given k. The efficiency mainly
depend on load factor.
Specially we are interested in following two quantities:
 S(λ) = average number of probes for a successful search
 U(λ) = average number of probes for an unsuccessful search
Open Addressing: Liner Probing and Modifications
 Suppose that new record R with key k is added to
memory table T, but that the memory location with hash
address H(k)=h is already filled.
One natural way to resolve the collision is to assign R to
the first variable locating following T[h] (we assume that
the table T with m location is circular i.e. T[1] comes after
T[m]).
With such a collision procedure, we will search for record R in
table T by linearly search the locations T[h], T[h+1], T[h+2],
…………. Until finding R or meeting empty location, which indicates
an unsuccessful search.
The above collision resolution is called Linear probing.
The average number of probes for load factor (λ =n/m) are:
EX: Linear Probing
Open Addressing
One main disadvantage of linear probing is that records
tend to cluster, that is, appear next to one another, when
the load factor is greater then 50%.
The two technique that minimize the clustering are as:
1. Quadratic probing: Suppose the record R with key K has
the hash address H(k)=h. Then instead of searching the
locations with address h, h+1, h+2, …….. ., we search the
location with address
h,h+1,h+4,h+9, …………..,h+i^2,……
2. Double hashing: here the second hash function H’ is used
for resolving a collision, as follows. Suppose a record R
with key k has a hash address H(k)=h and H’(k)=h’≠m.
Then we linearly search the locations with address
h, h+h’, h+2h’, h+3h’, …………
Chaining
Chaining involves maintaining two tables in memory.
First of all, as before, there is a table T in memory which
contains the records in F, except that T now has an
additional field LINK which is used so that all record in T
with same hash address h may be linked together to form
a linked list. Second, there is a hash address table LIST
which contain pointers to linked lists in T.
Suppose a new record R with key k is added to the file F.
we place R in the first available location in the table T and
then add R to the linked list with pointer LIST[H(k)].
The average number of probes for load factor (λ =n/m may be greater
than 1) are:
S(λ)≈1+ λ/2 and U(λ)≈e^(- λ)+ λ.
Ex: Chaining
Using chaining, the record will appear in memory as:
Data Structure and Algorithms Hashing
Ad

More Related Content

What's hot (20)

Hash table
Hash tableHash table
Hash table
Vu Tran
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
Saurabh Kumar
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Hashing
HashingHashing
Hashing
Ghaffar Khan
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
Krish_ver2
 
single linked list
single linked listsingle linked list
single linked list
Sathasivam Rangasamy
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Hashing
HashingHashing
Hashing
Amar Jukuntla
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
Edureka!
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
Vrushali Dhanokar
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
Aamir Sohail
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashing
sathish sak
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
Meghaj Mallick
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
Edureka!
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
Aamir Sohail
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashing
sathish sak
 

Similar to Data Structure and Algorithms Hashing (20)

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
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
chidabdu
 
Hashing components and its laws 2 types
Hashing  components and its laws  2 typesHashing  components and its laws  2 types
Hashing components and its laws 2 types
abhinavkumar77723
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
MuhammadUmerIhtisham
 
hashing explained in detail with hash functions
hashing explained in detail with hash functionshashing explained in detail with hash functions
hashing explained in detail with hash functions
gaurav77712
 
Tojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdv
Tojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdvTojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdv
Tojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdv
2021csabhishekgdurga
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
kratika64
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
KARANAMSANTOSH1
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
Sajid Marwat
 
13-hashing.ppt
13-hashing.ppt13-hashing.ppt
13-hashing.ppt
soniya555961
 
8. Hash table
8. Hash table8. Hash table
8. Hash table
Mandeep Singh
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
rajshreemuthiah
 
Hashing
HashingHashing
Hashing
amoldkul
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of technic
lokaprasaadvs
 
Hashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and analysis of AlgorithmsHashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and analysis of Algorithms
KavitaSingh962656
 
Hashing CollisionDetection in Data Structures
Hashing CollisionDetection in Data StructuresHashing CollisionDetection in Data Structures
Hashing CollisionDetection in Data Structures
LifnaCS1
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
Sam Light
 
Hashing 1
Hashing 1Hashing 1
Hashing 1
Shyam Khant
 
Lec5
Lec5Lec5
Lec5
Nikhil Chilwant
 
PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx
PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptxPPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx
PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx
CHANDUS31
 
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
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
chidabdu
 
Hashing components and its laws 2 types
Hashing  components and its laws  2 typesHashing  components and its laws  2 types
Hashing components and its laws 2 types
abhinavkumar77723
 
hashing explained in detail with hash functions
hashing explained in detail with hash functionshashing explained in detail with hash functions
hashing explained in detail with hash functions
gaurav77712
 
Tojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdv
Tojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdvTojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdv
Tojo Sir Hash Tables.pdfsfdasdasv fdsfdfsdv
2021csabhishekgdurga
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
kratika64
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
Sajid Marwat
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of technic
lokaprasaadvs
 
Hashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and analysis of AlgorithmsHashing in Data Structure and analysis of Algorithms
Hashing in Data Structure and analysis of Algorithms
KavitaSingh962656
 
Hashing CollisionDetection in Data Structures
Hashing CollisionDetection in Data StructuresHashing CollisionDetection in Data Structures
Hashing CollisionDetection in Data Structures
LifnaCS1
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
Sam Light
 
PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx
PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptxPPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx
PPT 2 wirha DSA hasings dvd ho gi of DJ of ch huu Raj of DJ.pptx
CHANDUS31
 
Ad

More from ManishPrajapati78 (15)

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms Sorting
ManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge SortData Structure and Algorithms Merge Sort
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Data Structure and Algorithms Sorting
Data Structure and Algorithms SortingData Structure and Algorithms Sorting
Data Structure and Algorithms Sorting
ManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Ad

Recently uploaded (20)

Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Download MathType Crack Version 2025???
Download MathType Crack  Version 2025???Download MathType Crack  Version 2025???
Download MathType Crack Version 2025???
Google
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Buy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training techBuy vs. Build: Unlocking the right path for your training tech
Buy vs. Build: Unlocking the right path for your training tech
Rustici Software
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 

Data Structure and Algorithms Hashing

  • 1. Hashing Introduction Hash Functions Hash Table Closed hashing(open addressing) Linear Probing Quadratic Probing Double hashing Open hashing(separate chaining)
  • 2. Hashing  The search time of each algorithm discussed so far depends on number n depends on the number n of items in the collection S of data. A searching Technique, called Hashing or Hash addressing, which is independent of number n. We assume that 1. there is a file F of n records with a set K of keys which unlikely determine the record in F. 2. F is maintained in memory by a Table T of m memory locations and L is the set of memory addresses of locations in T. 3. For notational convenience, the keys in K and Address L are Integers.
  • 3. Example Suppose A company with 250 employees assign a 5- digit employee number to each employee which is used as primary key in company’s employee file. We can use employee number as a address of record in memory. The search will require no comparisons at all. Unfortunately, this technique will require space for 1,00,000 memory locations, where as fewer locations would actually used. So, this trade off for time is not worth the expense.
  • 4. Hashing  The general idea of using the key to determine the address of record is an excellent idea, but it must be modified so that great deal of space is not wasted. This modification takes the form of a function H from the set K of keys in to set L of memory address.  H: K L , Is called a Hash Function or  Unfortunately, Such a function H may not yield distinct values: it is possible that two different keys k1 and k2 will yield the same hash address. This situation is called Collision, and some method must be used to resolve it.
  • 5. Hash Functions  the two principal criteria used in selecting a hash function H: K L are as follows: 1. The function H should be very easy and quick to compute. 2.The function H should as far as possible, uniformly distribute the hash address through out the set L so that there are minimum number of collision.
  • 6. Hash Functions 1. Division method: choose a number m larger than the number n of keys in K. (m is usually either a prime number or a number without small divisor) the hash function H is defined by H(k) = k (mod m) or H(k) = k (mod m) + 1. here k (mod m) denotes the reminder when k is divided by m. the second formula is used when we want a hash address to range from 1 to m rather than 0 to m-1. 2. Midsquare method: the key k is squared. Then the hash function H is defined by H(k) = l. where l is obtained by deleting digits from both end of k^2. 3. Folding Method: the key k is portioned into a number of parts, k1, k2, ……,kr, where each part is added togather, ignoring the last carry. H(k) = k1+k2+ ……………+Kr. Sometimes, for extra “milling”, the even numbered parts, k2, k4, …. Are each reversed befor addition.
  • 7. Example of Hash Functions  consider a company with 68 employees assigns a 4-digit employee number to each employee. Suppose L consists of 100 two-digit address: 00, 01, 02 , ……….99. we apply above hash functions to each of following employee numbers: 3205, 7148,2345. 1. Division Method: choose a prime number m close to 99, m=97. H(k)=k(mod m): H(3205)=4, H(7148)=67, H(2345)=17. 2. Midsquare Method: k= 3205 7148 2345 k^2= 10272025 51093904 5499025 H(k)= 72 93 99 3. Folding Method: chopping the key k into two parts and adding yield the following hash address: H(3205)=32+05=37, H(7148)=71+48=19, H(2345)=23+45=68 Or, H(3205)=32+50=82, H(7148)=71+84=55, H(2345)=23+54=77
  • 8. Collision Resolution Suppose we want to add a new record R with key K to our file F, but suppose the memory location address H(k) is already occupied. This situation is called Collision. There are two general ways to resolve collisions :  Open addressing,(array method)  Separate Chaining (linked list method) The particular procedure that one choose depends on many factors. One important factor is load factor (λ=n/m)i.e. ratio of number n of keys in K (number of records in F) to m of hash address in L. e.g. suppose a student class has 24 students and table has space for 365 records. The efficiency of hash function with a collision resolution procedure is measured by the average number of probes (key comparison) needed to find the location of record with a given k. The efficiency mainly depend on load factor. Specially we are interested in following two quantities:  S(λ) = average number of probes for a successful search  U(λ) = average number of probes for an unsuccessful search
  • 9. Open Addressing: Liner Probing and Modifications  Suppose that new record R with key k is added to memory table T, but that the memory location with hash address H(k)=h is already filled. One natural way to resolve the collision is to assign R to the first variable locating following T[h] (we assume that the table T with m location is circular i.e. T[1] comes after T[m]). With such a collision procedure, we will search for record R in table T by linearly search the locations T[h], T[h+1], T[h+2], …………. Until finding R or meeting empty location, which indicates an unsuccessful search. The above collision resolution is called Linear probing. The average number of probes for load factor (λ =n/m) are:
  • 11. Open Addressing One main disadvantage of linear probing is that records tend to cluster, that is, appear next to one another, when the load factor is greater then 50%. The two technique that minimize the clustering are as: 1. Quadratic probing: Suppose the record R with key K has the hash address H(k)=h. Then instead of searching the locations with address h, h+1, h+2, …….. ., we search the location with address h,h+1,h+4,h+9, …………..,h+i^2,…… 2. Double hashing: here the second hash function H’ is used for resolving a collision, as follows. Suppose a record R with key k has a hash address H(k)=h and H’(k)=h’≠m. Then we linearly search the locations with address h, h+h’, h+2h’, h+3h’, …………
  • 12. Chaining Chaining involves maintaining two tables in memory. First of all, as before, there is a table T in memory which contains the records in F, except that T now has an additional field LINK which is used so that all record in T with same hash address h may be linked together to form a linked list. Second, there is a hash address table LIST which contain pointers to linked lists in T. Suppose a new record R with key k is added to the file F. we place R in the first available location in the table T and then add R to the linked list with pointer LIST[H(k)]. The average number of probes for load factor (λ =n/m may be greater than 1) are: S(λ)≈1+ λ/2 and U(λ)≈e^(- λ)+ λ.
  • 13. Ex: Chaining Using chaining, the record will appear in memory as:
  翻译: