SlideShare una empresa de Scribd logo
1 de 25
ANALYSIS AND DESIGN
ALGORITHMS
HASHING
Lecture:16 DEBOLINA
PAN
contents:
Introduction to Hashing
• It is the combination of sorting and searching
developed to improve the searching
technique.Refers to storing of data as well as
retrieval of data.
sorting has lower bound of (nlogn),and searching has lower
bound of (logn).2 problems with searching followed by sorting
is
I. Sorting needs one time cost but searching needs less cost.
II. Sorting is dynamic process
Hashing has solution of all these problems.
Hash Table
A hash table generalizes the simpler notion of an
ordinary array. Directly addressing into an ordinary
array makes effective use of our ability to examine an
arbitrary position in an array in O(1)time.
When the number of keys actually stored is small
relative to the total number of possible keys, hash
tables become an effective alternative to directly
addressing an array.
since a hash table typically uses an array of size
proportional to the number of keys actually stored.
Instead of using the key as an array index directly, the
Importance of hashing:
hashing is an extremely effective and practical
technique:
• the basic dictionary operations require only O(1)
time on the average.
• “perfect hashing” can support searches in O(1) worst
case time, when the set of keys being stored is static
(that is, when the set of keys never changes once
stored).
− Second Outline
Level

Third Outline
Level
− Fourth Outline
Level

Fifth
Outline
Level

Sixth
Outline
Level
• Seventh Outline
LevelClick to edit
Master text styles
Hash Function
Define a function h which
works on keys and
generate an integer
value which is the
address of that key.
h:{0,1,…,(n-1)}->{0,1,…(m-
1)}
Here,n: number of keys
m:number of locations.
Suppose,n keys(k0,k1,…kn-
How to make good hash function?
• A good hash function satisfies (approximately) the assumption of simple uniform
hashing: each key is equally likely to hash to any of the m slots, independently of
where any other key has hashed to. Unfortunately, we typically have no way to
check this condition, since we rarely know the probability distribution from which
the keys are drawn. Moreover, the keys might not be drawn independently,
Occasionally we do know the distribution. For example, if we know that the
keys are random real numbers k independently and uniformly distributed in the
range 0 ≤k<1, then the hash function
h[k] =[km] satisfies the condition of simple uniform hashing.
− Second Outline
Level

Third Outline
Level
− Fourth Outline
Level

Fifth
Outline
Level

Sixth
Outline
Level
• Seventh Outline
LevelClick to edit
Master text styles
Chaining
• It is the oldest hashing
technique.
• “chaining” as a way to
handle “collisions,” in
which more than one
key maps to the same
array index.
• In picture,h(k2)->0,and
h(k4)->1,now if h(k5)-
>0,then what will
happen?
− Second Outline
Level

Third Outline
Level
− Fourth Outline
Level

Fifth
Outline
Level

Sixth
Outline
Level
• Seventh Outline
LevelClick to edit
Master text styles
Collision
• There is one hitch: two
keys may hash to the
same slot. We call this
situation a collision.
− Second Outline
Level

Third Outline
Level
− Fourth Outline
Level

Fifth
Outline
Level

Sixth
Outline
Level
• Seventh Outline
LevelClick to edit
Master text styles
Collision Resolution By Chaining
• Say,h(k2)->0,h(k4)->1
we put them in hash
table.
And then 1 key k5 comes
for which hash function
h(k5)->0,then we put
the new arriving key in
front of the previous
key having same hash
function value.as in
picture.
Analysis of hashing with chaining:
• Given a hash table T with m slots that stores n
elements, we define the load factor for T asᾳ
n/m, that is, the average number of elements
stored in a chain.Our analysis will be in terms
of which can beᾳ less than, equal to, or
greater than 1.
For worst case:
The worst-case behavior of hashing with chaining is
terrible: all n keys hash to the same slot, creating a list
of length n.
The worst-case time for searching is thus (n) plus theӨ
time to compute the hash function—no better than if
we used one linked list for all the elements. Clearly, we
do not use hash tables for their worst-case
performance
For Average Case
• average-case performance of hashing depends on
how well the hash function h distributes the set of
keys to be stored among the m slots, on the average.
• Assumption: any given element is equally likely to
hash into any of the m slots, independently of where
any other element has hashed to. We call this the
assumption of simple uniform hashing
For j=0 to m-1,lett us denote the length of list T[j] by
nj ,so that n=n0+n1+...+nm-1.
and the expected value of nj is E[nj ] = =(n/m).ᾳ
Contd.
• We assume that (1) time suffices to compute theӨ
hash value h(k) so that the time required to search
for an element with key k depends linearly on the
length nh(k) of the list T[h(k)]. Setting aside the (1)Ө
time required to compute the hash function and to
access slot h(k) let us consider the expected number
of elements examined by the search algorithm, that
is, the number of elements in the list T[h(k)] that the
algorithm checks to see whether any have a key
equal to k. We shall consider two cases. In the first,
the search is unsuccessful: no element in the table
has key k. In the second, the search successfully finds
For Unsuccessful Search
In a hash table in which collisions are resolved by chaining, an unsuccessful search
takes average-case time‚ ( +1) under the assumption of simple uniform hashing.Ө ᾳ
Proof:
assumption: simple uniform hashing, any key k (not already
stored in the table) is equally likely to hash to any of the m slots.
The expected time
to search unsuccessfully for a key k is the expected time to search to the end of
list T[h(k)], which has expected length E(nh(k)= . Thus, the expected numberᾳ
of elements examined in an unsuccessful search is , and the total time requireᾳ
(including the time for computing h(k) ) is ( +1)Ө ᾳ ‚ The situation for a successful
search is slightly different, since each list is not equally likely to be searched. Instead,
For Successful Search
• In a hash table in which collisions are resolved by
chaining, a successful search takes average-case
time‚ (1+ ) under the assumption of simpleӨ ᾳ
uniform hashing.
• Proof:
• assumption:We assume that the element being
searched for is equally likely to be any of the n
elements stored in the table.
• The number of elements examined during a
successful search for an element x is one more than
Continued:
we have Pr {h(ki)= h(kj)}=1/m, and so E[xij]=1/m. Thus,
the expected number of elements examined in a
successful search is
E[1/n* ∑i=1 to n (1+∑j=(i+1) to n)Xij]
= 1/n* ∑i=1 to n 1+∑ j=(i+1) to n (xij)
= 1/n* ∑i=1 to n 1+∑ j=(i+1) to n (1/m)
= 1/n* ∑i=1 to n (1+1/m∑ j=(i+1) to n 1)
= 1/n* ∑i=1 to n 1+1/m(n-i)
Continued:
If the number of hash-table slots is at least proportional
to the number of elements in the table, we have
n=O(m) and, consequently, =n/m =O(m)/m=1. Thus,ᾳ
searching takes constant time on average. Since
insertion takes O(1) worst-case time and deletion takes
O(1) worst-case time when the lists are doubly linked,
we can support all dictionary operations in O(1)time on
average.
Open Addressing
• In open addressing, all elements occupy the
hash table itself. That is, each table entry
contains either an element of the dynamic set
or NIL. When searching for an element, we
systematically examine table slots until either
we find the desired element or we have
ascertained that the element is not in the
table. No lists andno elements are stored
outside the table, unlike in chaining. Thus, in
open addressing, the hash table can “fill up”
Open Addressing
• Of course, we could store the linked lists for
chaining inside the hash table, in the
otherwise unused hash-table slots
• advantage of open addressing is that it avoids
pointers altogether. Instead of following
pointers, we compute the sequence of slots to
be examined. The extra memory freed by not
storing pointers provides the hash table with a
larger number of slots for the same amount of
memory, potentially yielding fewer collisions
Probe & probe sequence
• To perform insertion using open addressing,
we successively examine, or probe, the hash
table until we find an empty slot in which to
put the key. Instead of being fixed in the order
0,1,..., m-1 (which requires (n) search time),Ө
the sequence of positions probed depends
upon the key being inserted. To determine
which slots to probe, we extend the hash
function to include the probe number
(starting from 0) as a second input. Thus, the
− Second Outline
Level

Third Outline
Level
− Fourth Outline
Level

Fifth
Outline
Level

Sixth
Outline
Level
• Seventh Outline
LevelClick to edit
Master text styles
How open addressing works
must be ≤1,ᾳ because
here instead of making
a chain we put the
element in table,and
table keeos the address.
Ki is given.1st initialize the
whole table is
blank,now,1<-
h(k3),then 0<-h(k4),if
now h(k5)->1 arrives
what will happen?
− Second Outline
Level

Third Outline
Level
− Fourth Outline
Level

Fifth
Outline
Level

Sixth
Outline
Level
• Seventh Outline
LevelClick to edit
Master text styles
Collision & new position
• 2 keys claiming same
location,collision
happens
• After collision we will
find a new location,this
is called probing.
• A type of probing is
linear probing
Linear Probing
Checks the next location,if it is blank,repeat
untill a blank space is found.if m>>n(that
means number of locations are much much
greater than number of elements) then no
collision.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
 
Hashing
HashingHashing
Hashing
 
Hashing data
Hashing dataHashing data
Hashing data
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
linear probing
linear probinglinear probing
linear probing
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Hash table
Hash tableHash table
Hash table
 
Hashing
HashingHashing
Hashing
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Application of hashing in better alg design tanmay
Application of hashing in better alg design tanmayApplication of hashing in better alg design tanmay
Application of hashing in better alg design tanmay
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
18 hashing
18 hashing18 hashing
18 hashing
 
Hashing
HashingHashing
Hashing
 
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
 
Hashing
HashingHashing
Hashing
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
Hashing
HashingHashing
Hashing
 

Destacado

Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2debolina13
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1debolina13
 
Preparation Data Structures 02 recursion
Preparation Data Structures 02 recursionPreparation Data Structures 02 recursion
Preparation Data Structures 02 recursionAndres Mendez-Vazquez
 
07.2 Holland's Genetic Algorithms Schema Theorem
07.2 Holland's Genetic Algorithms Schema Theorem07.2 Holland's Genetic Algorithms Schema Theorem
07.2 Holland's Genetic Algorithms Schema TheoremAndres Mendez-Vazquez
 
Coalesced hashing / Hash Coalescido
Coalesced hashing / Hash CoalescidoCoalesced hashing / Hash Coalescido
Coalesced hashing / Hash CoalescidoCriatividadeZeroDocs
 
Cs6402 design and analysis of algorithms impartant part b questions appasami
Cs6402 design and analysis of algorithms  impartant part b questions appasamiCs6402 design and analysis of algorithms  impartant part b questions appasami
Cs6402 design and analysis of algorithms impartant part b questions appasamiappasami
 
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioCS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioKarthik Venkatachalam
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyappasami
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 

Destacado (19)

Android
AndroidAndroid
Android
 
Dynamic programmng2
Dynamic programmng2Dynamic programmng2
Dynamic programmng2
 
algorithm unit 1
algorithm unit 1algorithm unit 1
algorithm unit 1
 
Data representation UNIT-1
Data representation UNIT-1Data representation UNIT-1
Data representation UNIT-1
 
ELEMENTARY DATASTRUCTURES
ELEMENTARY DATASTRUCTURESELEMENTARY DATASTRUCTURES
ELEMENTARY DATASTRUCTURES
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1
 
Preparation Data Structures 02 recursion
Preparation Data Structures 02 recursionPreparation Data Structures 02 recursion
Preparation Data Structures 02 recursion
 
07.2 Holland's Genetic Algorithms Schema Theorem
07.2 Holland's Genetic Algorithms Schema Theorem07.2 Holland's Genetic Algorithms Schema Theorem
07.2 Holland's Genetic Algorithms Schema Theorem
 
Coalesced hashing / Hash Coalescido
Coalesced hashing / Hash CoalescidoCoalesced hashing / Hash Coalescido
Coalesced hashing / Hash Coalescido
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
 
Cs6402 design and analysis of algorithms impartant part b questions appasami
Cs6402 design and analysis of algorithms  impartant part b questions appasamiCs6402 design and analysis of algorithms  impartant part b questions appasami
Cs6402 design and analysis of algorithms impartant part b questions appasami
 
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioCS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
 
Hash tables
Hash tablesHash tables
Hash tables
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 

Similar a ANALYSIS AND DESIGN ALGORITHMS: HASHING TECHNIQUES

Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingSam Light
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingzukun
 
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 techniclokaprasaadvs
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashingRafi Dar
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7chidabdu
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec IISajid Marwat
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashingchidabdu
 
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 algorithmfarhankhan89766
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxjainaaru59
 
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.pptxmy6305874
 

Similar a ANALYSIS AND DESIGN ALGORITHMS: HASHING TECHNIQUES (20)

Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
13-hashing.ppt
13-hashing.ppt13-hashing.ppt
13-hashing.ppt
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sorting
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
 
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
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
Algorithm chapter 7
Algorithm chapter 7Algorithm chapter 7
Algorithm chapter 7
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
Sienna 9 hashing
Sienna 9 hashingSienna 9 hashing
Sienna 9 hashing
 
lecture10.ppt
lecture10.pptlecture10.ppt
lecture10.ppt
 
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
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
session 15 hashing.pptx
session 15   hashing.pptxsession 15   hashing.pptx
session 15 hashing.pptx
 
Lec4
Lec4Lec4
Lec4
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptx
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptx
 

Último

Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 

Último (20)

Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 

ANALYSIS AND DESIGN ALGORITHMS: HASHING TECHNIQUES

  • 3. Introduction to Hashing • It is the combination of sorting and searching developed to improve the searching technique.Refers to storing of data as well as retrieval of data. sorting has lower bound of (nlogn),and searching has lower bound of (logn).2 problems with searching followed by sorting is I. Sorting needs one time cost but searching needs less cost. II. Sorting is dynamic process Hashing has solution of all these problems.
  • 4. Hash Table A hash table generalizes the simpler notion of an ordinary array. Directly addressing into an ordinary array makes effective use of our ability to examine an arbitrary position in an array in O(1)time. When the number of keys actually stored is small relative to the total number of possible keys, hash tables become an effective alternative to directly addressing an array. since a hash table typically uses an array of size proportional to the number of keys actually stored. Instead of using the key as an array index directly, the
  • 5. Importance of hashing: hashing is an extremely effective and practical technique: • the basic dictionary operations require only O(1) time on the average. • “perfect hashing” can support searches in O(1) worst case time, when the set of keys being stored is static (that is, when the set of keys never changes once stored).
  • 6. − Second Outline Level  Third Outline Level − Fourth Outline Level  Fifth Outline Level  Sixth Outline Level • Seventh Outline LevelClick to edit Master text styles Hash Function Define a function h which works on keys and generate an integer value which is the address of that key. h:{0,1,…,(n-1)}->{0,1,…(m- 1)} Here,n: number of keys m:number of locations. Suppose,n keys(k0,k1,…kn-
  • 7. How to make good hash function? • A good hash function satisfies (approximately) the assumption of simple uniform hashing: each key is equally likely to hash to any of the m slots, independently of where any other key has hashed to. Unfortunately, we typically have no way to check this condition, since we rarely know the probability distribution from which the keys are drawn. Moreover, the keys might not be drawn independently, Occasionally we do know the distribution. For example, if we know that the keys are random real numbers k independently and uniformly distributed in the range 0 ≤k<1, then the hash function h[k] =[km] satisfies the condition of simple uniform hashing.
  • 8. − Second Outline Level  Third Outline Level − Fourth Outline Level  Fifth Outline Level  Sixth Outline Level • Seventh Outline LevelClick to edit Master text styles Chaining • It is the oldest hashing technique. • “chaining” as a way to handle “collisions,” in which more than one key maps to the same array index. • In picture,h(k2)->0,and h(k4)->1,now if h(k5)- >0,then what will happen?
  • 9. − Second Outline Level  Third Outline Level − Fourth Outline Level  Fifth Outline Level  Sixth Outline Level • Seventh Outline LevelClick to edit Master text styles Collision • There is one hitch: two keys may hash to the same slot. We call this situation a collision.
  • 10. − Second Outline Level  Third Outline Level − Fourth Outline Level  Fifth Outline Level  Sixth Outline Level • Seventh Outline LevelClick to edit Master text styles Collision Resolution By Chaining • Say,h(k2)->0,h(k4)->1 we put them in hash table. And then 1 key k5 comes for which hash function h(k5)->0,then we put the new arriving key in front of the previous key having same hash function value.as in picture.
  • 11. Analysis of hashing with chaining:
  • 12. • Given a hash table T with m slots that stores n elements, we define the load factor for T asᾳ n/m, that is, the average number of elements stored in a chain.Our analysis will be in terms of which can beᾳ less than, equal to, or greater than 1.
  • 13. For worst case: The worst-case behavior of hashing with chaining is terrible: all n keys hash to the same slot, creating a list of length n. The worst-case time for searching is thus (n) plus theӨ time to compute the hash function—no better than if we used one linked list for all the elements. Clearly, we do not use hash tables for their worst-case performance
  • 14. For Average Case • average-case performance of hashing depends on how well the hash function h distributes the set of keys to be stored among the m slots, on the average. • Assumption: any given element is equally likely to hash into any of the m slots, independently of where any other element has hashed to. We call this the assumption of simple uniform hashing For j=0 to m-1,lett us denote the length of list T[j] by nj ,so that n=n0+n1+...+nm-1. and the expected value of nj is E[nj ] = =(n/m).ᾳ
  • 15. Contd. • We assume that (1) time suffices to compute theӨ hash value h(k) so that the time required to search for an element with key k depends linearly on the length nh(k) of the list T[h(k)]. Setting aside the (1)Ө time required to compute the hash function and to access slot h(k) let us consider the expected number of elements examined by the search algorithm, that is, the number of elements in the list T[h(k)] that the algorithm checks to see whether any have a key equal to k. We shall consider two cases. In the first, the search is unsuccessful: no element in the table has key k. In the second, the search successfully finds
  • 16. For Unsuccessful Search In a hash table in which collisions are resolved by chaining, an unsuccessful search takes average-case time‚ ( +1) under the assumption of simple uniform hashing.Ө ᾳ Proof: assumption: simple uniform hashing, any key k (not already stored in the table) is equally likely to hash to any of the m slots. The expected time to search unsuccessfully for a key k is the expected time to search to the end of list T[h(k)], which has expected length E(nh(k)= . Thus, the expected numberᾳ of elements examined in an unsuccessful search is , and the total time requireᾳ (including the time for computing h(k) ) is ( +1)Ө ᾳ ‚ The situation for a successful search is slightly different, since each list is not equally likely to be searched. Instead,
  • 17. For Successful Search • In a hash table in which collisions are resolved by chaining, a successful search takes average-case time‚ (1+ ) under the assumption of simpleӨ ᾳ uniform hashing. • Proof: • assumption:We assume that the element being searched for is equally likely to be any of the n elements stored in the table. • The number of elements examined during a successful search for an element x is one more than
  • 18. Continued: we have Pr {h(ki)= h(kj)}=1/m, and so E[xij]=1/m. Thus, the expected number of elements examined in a successful search is E[1/n* ∑i=1 to n (1+∑j=(i+1) to n)Xij] = 1/n* ∑i=1 to n 1+∑ j=(i+1) to n (xij) = 1/n* ∑i=1 to n 1+∑ j=(i+1) to n (1/m) = 1/n* ∑i=1 to n (1+1/m∑ j=(i+1) to n 1) = 1/n* ∑i=1 to n 1+1/m(n-i)
  • 19. Continued: If the number of hash-table slots is at least proportional to the number of elements in the table, we have n=O(m) and, consequently, =n/m =O(m)/m=1. Thus,ᾳ searching takes constant time on average. Since insertion takes O(1) worst-case time and deletion takes O(1) worst-case time when the lists are doubly linked, we can support all dictionary operations in O(1)time on average.
  • 20. Open Addressing • In open addressing, all elements occupy the hash table itself. That is, each table entry contains either an element of the dynamic set or NIL. When searching for an element, we systematically examine table slots until either we find the desired element or we have ascertained that the element is not in the table. No lists andno elements are stored outside the table, unlike in chaining. Thus, in open addressing, the hash table can “fill up”
  • 21. Open Addressing • Of course, we could store the linked lists for chaining inside the hash table, in the otherwise unused hash-table slots • advantage of open addressing is that it avoids pointers altogether. Instead of following pointers, we compute the sequence of slots to be examined. The extra memory freed by not storing pointers provides the hash table with a larger number of slots for the same amount of memory, potentially yielding fewer collisions
  • 22. Probe & probe sequence • To perform insertion using open addressing, we successively examine, or probe, the hash table until we find an empty slot in which to put the key. Instead of being fixed in the order 0,1,..., m-1 (which requires (n) search time),Ө the sequence of positions probed depends upon the key being inserted. To determine which slots to probe, we extend the hash function to include the probe number (starting from 0) as a second input. Thus, the
  • 23. − Second Outline Level  Third Outline Level − Fourth Outline Level  Fifth Outline Level  Sixth Outline Level • Seventh Outline LevelClick to edit Master text styles How open addressing works must be ≤1,ᾳ because here instead of making a chain we put the element in table,and table keeos the address. Ki is given.1st initialize the whole table is blank,now,1<- h(k3),then 0<-h(k4),if now h(k5)->1 arrives what will happen?
  • 24. − Second Outline Level  Third Outline Level − Fourth Outline Level  Fifth Outline Level  Sixth Outline Level • Seventh Outline LevelClick to edit Master text styles Collision & new position • 2 keys claiming same location,collision happens • After collision we will find a new location,this is called probing. • A type of probing is linear probing
  • 25. Linear Probing Checks the next location,if it is blank,repeat untill a blank space is found.if m>>n(that means number of locations are much much greater than number of elements) then no collision.