SlideShare una empresa de Scribd logo
1 de 29
HASHING
UNIVERSITY OF AZAD JAMMU & KASHMIR
MUZAFFARABAD
DEPARTMENT OF CS&IT
DATA STRUCTURE
• Dawood Faheem Abbasi BSCS-III-05
OUTLINE1. Searching methods
– Linear search
– Binary search
– Hashing
• Introduction
• Dictionary
• Hash table
• Working of hash table
• Hash functions
– Division method
– Mid square method
– Folding method
• Algorithm
• Characteristics of good hash function
• Collision
• Collision resolution
– Separate chaining
– Closed hashing
• Applications of hashing
SEARCHING METHODS
• Sequential or Linear Searching.
• Binary Search.
• Hashing.
SEQUENTIAL SEARCH
• Searches on unordered and ordered tables in sequential manner until the desired record is
not found or table end is not reached.
• It is simple and good for small arrays.
• Mostly used when data is not sorted.
• Less efficient if array size is large.
• Consumes a lot of time as compared to other techniques.
• Not efficient on sorted arrays.
BINARY SORT
• This technique works better on sorted arrays and can be applied only on sorted
arrays.
• Not applied on Linked Lists.
• Requires less number of comparisons than linear search.
• Efficiency: O(log2n).
• Logic behind the technique:
Second HalfFirst Half
mid=(low+high)/2
Last ValueFirst Value
EFFICIENCY:
• Best – O(1)
Constant time
• Average – O(n/2)
Here, n represents the number of elements in array
• Worst – O(n)
Here, n represents the number of elements in array
Apply NowApply NowApply Now
ILLUSTRATION OF ZIP FILE
HASHING
INTRODUCTION
Hashing is the transformation of long strings or information into a usually
shorter fixed-length value or key that represents the original string or
information.
Hashing is used to index and retrieve items in a database because it is
faster to find the item using the shorter hashed key than to find it using the
original value.
 It is also used in many encryption algorithms.
A table of records in which a key is used for retrieval is often called a
SEARCH TABLE or DICTIONARY.
DICTIONARY
• A dictionary is a collection of elements
• Each element has a field called key
– (key, value)
• Every key is usually distinct.
• Typical dictionary operations are:
– Insert a pair into the dictionary
– Search the pair with a specified key
– Delete the pair with a specified key
HASH TABLE
• A hash table is a data structure that stores elements and allows insertions,
lookups, and deletions to be performed in O(1) time.
• A hash table is an alternative method for representing a dictionary
• In a hash table, a hash function is used to map keys into positions in a table.
This act is called hashing
• Hash Table Operations
– Search: compute f(k) and see if a pair exists
– Insert: compute f(k) and place it in that position
– Delete: compute f(k) and delete the pair in that position
• In ideal situation, hash table search, insert or delete takes (1)
WORKING OF HASH TABLE
• The table part is just an ordinary array, it is the Hash that we are interested in.
• The Hash is a function that transforms a key into address or index of array(table)
where the record will be stored. If the size of the table is N, then the integer will be in
the range 0 to N-1. The integer is used as an index into the array. Thus, in
essence, the key itself indexes the array.
• If h is a hash function and k is key then h(k) is called the hash of the key and is the
index at which a record with the key k should be placed.
• The hash function generates this address by performing some simple arithmetic or
logical operations on the key
HASH FUNCTIONS
• It Is the technique of using key to determine the address of a record so that no space
is wasted.
• Division method or function
• Mid-square method or function
• Folding method or function
DIVISION METHOD
• Division method computes the value of Hash as the remainder when the key is divided
by a specified prime number or it can be the size of the table.
• The hash function is defined as
H(k)=K( mod m)
Where K is the key and m is a prime number or size of the table.
MIDSQUARE METHOD
• In this method we squared the KEY and then the HASH FUNCTION is defined as:
H(K)=I
Where I is the value which
we obtain by deleting equal digits
from both sides ok K(square).
EXAMPLE
• Followings are some keys
k= 4012 8090
K (sqr)= 16096144 65448100
H( k)= 96 48
FOLDING METHOD
• In this method we divide the key value in two parts. And then we add them.
FOR EXAMPLE:
K= 4012 1027
40+12=52 10+27=37
J=52 J=37
Here J is the value which we obtain by adding the KEY value.
ALGORITHM
• Our goal in choosing any hashing algorithm is to spread out the record as uniformly as
possible over the range of addresses available
• It has three steps
• Represent the key in any numerical form
• Fold and add
• Divide by the size of the address space and use the reminder as an address.
EXAMPLE
• Pairs are: (22,a),(33,c),(3,d),(72,e),(85,f)--(key, value) pairs
• Hash table is ht[0:7], m = 8 (where m is the number of positions in the hash table)
• Hash function h is k % m = k % 8
• Where are the pairs stored?
[0] [1] [2] [3] [4] [5] [6] [7]
[0] [1] [2] [3] [4] [5] [6] [7]
(72,e) (33,c) (85,f) (22,a)(3,d)
CHARACTERISTICS OF GOOD HASH
FUNCTION
The hash value is fully determined by the data being hashed.
The hash function uses all the input data.
The hash function "uniformly" distributes the data across the entire set of possible
hash values.
The hash function generates very different hash values for similar strings.
COLLISIONS AND THEIR RESOLUTION
• A collision occurs when two different keys hash to the same value
– E.g. For Table Size = 17, the keys 18 and 35 hash to the same value
– 18 mod 17 = 1 and 35 mod 17 = 1
• Cannot store both data records in the same slot in array!
COLLISION RESOLUTION
A method that is used to resolve the collision in Hash function is called Collision Resolution.
• Two different methods for collision resolution:
– Separate Chaining: Use a dictionary data structure (such as a linked list) to
store multiple items that hash to the same slot
– Closed Hashing (or probing): search for empty slots using a second function
and store item in first empty slot that is found
SEPARATE CHAINING
• Put a little dictionary at each entry
– choose type as appropriate
– common case is unordered linked list (chain)
• Properties
– performance degrades with length of chains
–  can be greater than 1
3
2
1
0
6
5
4
a d
e b
c
h(a) = h(d)
h(e) = h(b)
CLOSED HASHING
Problem with separate chaining:
Memory consumed by pointers –
What if we only allow one Key at each entry?
– two objects that hash to the same spot can’t both go there
– first one there gets the spot
– next one must go in another spot
• Properties
– performance degrades with difficulty of finding right spot
a
c
e
3
2
1
0
6
5
4
h(a) = h(d)
h(e) = h(b)
d
b
APPLICATIONS
• File management- working out where to store records
• Comparing complex values
• Cryptography- creating digital signatures and passwords.
• Dictionaries
• Security systems
THANK YOUT A K E A S M I L E , T H E Y A R E F R E E


Más contenido relacionado

La actualidad más candente

Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms HashingManishPrajapati78
 
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 algorithmAamir Sohail
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its usesJawad Khan
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
Bubble sort
Bubble sortBubble sort
Bubble sortManek Ar
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 

La actualidad más candente (20)

Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms 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
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Hash tables
Hash tablesHash tables
Hash tables
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 

Destacado

Destacado (13)

Hashing
HashingHashing
Hashing
 
Coalesced hashing / Hash Coalescido
Coalesced hashing / Hash CoalescidoCoalesced hashing / Hash Coalescido
Coalesced hashing / Hash Coalescido
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
Hashing Algorithm
Hashing AlgorithmHashing Algorithm
Hashing Algorithm
 
SEO Website Analysis - example report
SEO Website Analysis - example reportSEO Website Analysis - example report
SEO Website Analysis - example report
 
Seo analysis report template (1)
Seo analysis report template (1)Seo analysis report template (1)
Seo analysis report template (1)
 
Hash tables
Hash tablesHash tables
Hash tables
 
Html, CSS & Web Designing
Html, CSS & Web DesigningHtml, CSS & Web Designing
Html, CSS & Web Designing
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer Science
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Web Development on Web Project Report
Web Development on Web Project ReportWeb Development on Web Project Report
Web Development on Web Project Report
 
E commerce project report
E commerce project report E commerce project report
E commerce project report
 
Website analysis sample report
Website analysis sample reportWebsite analysis sample report
Website analysis sample report
 

Similar a Hashing Techniques for Fast Data Retrieval

Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing TablesChinmaya M. N
 
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 techniquesssuserec8a711
 
Hash table
Hash tableHash table
Hash tableVu Tran
 
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.pptxBabaShaikh3
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashingAkhil Prem
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptxDr.Shweta
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
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
 
Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT icajiwol341
 
Chapter 4.pptx
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptxTekle12
 
Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxSLekshmiNair
 

Similar a Hashing Techniques for Fast Data Retrieval (20)

Hashing
HashingHashing
Hashing
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 
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
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
Hashing
HashingHashing
Hashing
 
Hash table
Hash tableHash table
Hash table
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
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
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
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
 
Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
Chapter 4.pptx
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptx
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptx
 
Searching
SearchingSearching
Searching
 
Hash tables
Hash tablesHash tables
Hash tables
 

Más de Dawood Faheem Abbasi (11)

First and follow set
First and follow setFirst and follow set
First and follow set
 
TCP/IP and UDP protocols
TCP/IP and UDP protocolsTCP/IP and UDP protocols
TCP/IP and UDP protocols
 
Report writing
Report writingReport writing
Report writing
 
UML constructs
UML constructs UML constructs
UML constructs
 
Mathematical induction and divisibility rules
Mathematical induction and divisibility rulesMathematical induction and divisibility rules
Mathematical induction and divisibility rules
 
Features of-RC-quad-copter
Features of-RC-quad-copter Features of-RC-quad-copter
Features of-RC-quad-copter
 
7 cs of communication
7 cs of communication7 cs of communication
7 cs of communication
 
Geography of pakistan
Geography of pakistanGeography of pakistan
Geography of pakistan
 
FET (Field Effect Transistors)
FET (Field Effect Transistors)FET (Field Effect Transistors)
FET (Field Effect Transistors)
 
Cyber crime.pptx
Cyber crime.pptxCyber crime.pptx
Cyber crime.pptx
 
BJT’s (bipolar junction transistor)
BJT’s (bipolar junction transistor)BJT’s (bipolar junction transistor)
BJT’s (bipolar junction transistor)
 

Último

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Último (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Hashing Techniques for Fast Data Retrieval

  • 1.
  • 3. UNIVERSITY OF AZAD JAMMU & KASHMIR MUZAFFARABAD DEPARTMENT OF CS&IT DATA STRUCTURE • Dawood Faheem Abbasi BSCS-III-05
  • 4. OUTLINE1. Searching methods – Linear search – Binary search – Hashing • Introduction • Dictionary • Hash table • Working of hash table • Hash functions – Division method – Mid square method – Folding method • Algorithm • Characteristics of good hash function • Collision • Collision resolution – Separate chaining – Closed hashing • Applications of hashing
  • 5. SEARCHING METHODS • Sequential or Linear Searching. • Binary Search. • Hashing.
  • 6. SEQUENTIAL SEARCH • Searches on unordered and ordered tables in sequential manner until the desired record is not found or table end is not reached. • It is simple and good for small arrays. • Mostly used when data is not sorted. • Less efficient if array size is large. • Consumes a lot of time as compared to other techniques. • Not efficient on sorted arrays.
  • 7. BINARY SORT • This technique works better on sorted arrays and can be applied only on sorted arrays. • Not applied on Linked Lists. • Requires less number of comparisons than linear search. • Efficiency: O(log2n). • Logic behind the technique: Second HalfFirst Half mid=(low+high)/2 Last ValueFirst Value
  • 8. EFFICIENCY: • Best – O(1) Constant time • Average – O(n/2) Here, n represents the number of elements in array • Worst – O(n) Here, n represents the number of elements in array Apply NowApply NowApply Now
  • 11. INTRODUCTION Hashing is the transformation of long strings or information into a usually shorter fixed-length value or key that represents the original string or information. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value.  It is also used in many encryption algorithms. A table of records in which a key is used for retrieval is often called a SEARCH TABLE or DICTIONARY.
  • 12. DICTIONARY • A dictionary is a collection of elements • Each element has a field called key – (key, value) • Every key is usually distinct. • Typical dictionary operations are: – Insert a pair into the dictionary – Search the pair with a specified key – Delete the pair with a specified key
  • 13. HASH TABLE • A hash table is a data structure that stores elements and allows insertions, lookups, and deletions to be performed in O(1) time. • A hash table is an alternative method for representing a dictionary • In a hash table, a hash function is used to map keys into positions in a table. This act is called hashing • Hash Table Operations – Search: compute f(k) and see if a pair exists – Insert: compute f(k) and place it in that position – Delete: compute f(k) and delete the pair in that position • In ideal situation, hash table search, insert or delete takes (1)
  • 14. WORKING OF HASH TABLE • The table part is just an ordinary array, it is the Hash that we are interested in. • The Hash is a function that transforms a key into address or index of array(table) where the record will be stored. If the size of the table is N, then the integer will be in the range 0 to N-1. The integer is used as an index into the array. Thus, in essence, the key itself indexes the array. • If h is a hash function and k is key then h(k) is called the hash of the key and is the index at which a record with the key k should be placed. • The hash function generates this address by performing some simple arithmetic or logical operations on the key
  • 15. HASH FUNCTIONS • It Is the technique of using key to determine the address of a record so that no space is wasted. • Division method or function • Mid-square method or function • Folding method or function
  • 16. DIVISION METHOD • Division method computes the value of Hash as the remainder when the key is divided by a specified prime number or it can be the size of the table. • The hash function is defined as H(k)=K( mod m) Where K is the key and m is a prime number or size of the table.
  • 17.
  • 18. MIDSQUARE METHOD • In this method we squared the KEY and then the HASH FUNCTION is defined as: H(K)=I Where I is the value which we obtain by deleting equal digits from both sides ok K(square).
  • 19. EXAMPLE • Followings are some keys k= 4012 8090 K (sqr)= 16096144 65448100 H( k)= 96 48
  • 20. FOLDING METHOD • In this method we divide the key value in two parts. And then we add them. FOR EXAMPLE: K= 4012 1027 40+12=52 10+27=37 J=52 J=37 Here J is the value which we obtain by adding the KEY value.
  • 21. ALGORITHM • Our goal in choosing any hashing algorithm is to spread out the record as uniformly as possible over the range of addresses available • It has three steps • Represent the key in any numerical form • Fold and add • Divide by the size of the address space and use the reminder as an address.
  • 22. EXAMPLE • Pairs are: (22,a),(33,c),(3,d),(72,e),(85,f)--(key, value) pairs • Hash table is ht[0:7], m = 8 (where m is the number of positions in the hash table) • Hash function h is k % m = k % 8 • Where are the pairs stored? [0] [1] [2] [3] [4] [5] [6] [7] [0] [1] [2] [3] [4] [5] [6] [7] (72,e) (33,c) (85,f) (22,a)(3,d)
  • 23. CHARACTERISTICS OF GOOD HASH FUNCTION The hash value is fully determined by the data being hashed. The hash function uses all the input data. The hash function "uniformly" distributes the data across the entire set of possible hash values. The hash function generates very different hash values for similar strings.
  • 24. COLLISIONS AND THEIR RESOLUTION • A collision occurs when two different keys hash to the same value – E.g. For Table Size = 17, the keys 18 and 35 hash to the same value – 18 mod 17 = 1 and 35 mod 17 = 1 • Cannot store both data records in the same slot in array!
  • 25. COLLISION RESOLUTION A method that is used to resolve the collision in Hash function is called Collision Resolution. • Two different methods for collision resolution: – Separate Chaining: Use a dictionary data structure (such as a linked list) to store multiple items that hash to the same slot – Closed Hashing (or probing): search for empty slots using a second function and store item in first empty slot that is found
  • 26. SEPARATE CHAINING • Put a little dictionary at each entry – choose type as appropriate – common case is unordered linked list (chain) • Properties – performance degrades with length of chains –  can be greater than 1 3 2 1 0 6 5 4 a d e b c h(a) = h(d) h(e) = h(b)
  • 27. CLOSED HASHING Problem with separate chaining: Memory consumed by pointers – What if we only allow one Key at each entry? – two objects that hash to the same spot can’t both go there – first one there gets the spot – next one must go in another spot • Properties – performance degrades with difficulty of finding right spot a c e 3 2 1 0 6 5 4 h(a) = h(d) h(e) = h(b) d b
  • 28. APPLICATIONS • File management- working out where to store records • Comparing complex values • Cryptography- creating digital signatures and passwords. • Dictionaries • Security systems
  • 29. THANK YOUT A K E A S M I L E , T H E Y A R E F R E E 