SlideShare a Scribd company logo
Hashing
Amar Jukuntla
Index
• Introduction
• Advantages
• Hash Function
• Hash Table
• Collision Resolution Techniques
• Separate Chaining
• Linear Chaining
• Quadratic Probing
• Double Hashing
• Application
• Reference
Introduction
• Hashing is a technique that is used to uniquely identify
a specific object from a group of similar objects.
• Some examples of how hashing is used in our lives include:
• In universities, each student is assigned a unique roll number that can be
used to retrieve information about them.
• In libraries, each book is assigned a unique number that can be used to
determine information about the book, such as its exact position in the
library or the users it has been issued to etc.
• In both these examples the students and books were hashed to a
unique number.
Continue…
• Assume that you have an object and you want to assign
a key to it to make searching easy. To store the
key/value pair, you can use a simple array like a data
structure where keys (integers) can be used directly as
an index to store values. However, in cases where the
keys are large and cannot be used directly as an index,
you should use hashing.
Continue…
• In hashing, large keys are converted into small keys
by using hash functions.
• The values are then stored in a data structure called hash table.
• The idea of hashing is to distribute entries (key/value pairs)
uniformly across an array.
• Each element is assigned a key (converted key).
• By using that key you can access the element in O(1) time. Using
the key, the algorithm (hash function) computes an index that
suggests where an entry can be found or inserted.
Continue…
• Hashing is implemented in two steps:
• An element is converted into an integer by using a hash
function. This element can be used as an index to store the
original element, which falls into the hash table.
• The element is stored in the hash table where it can be quickly
retrieved using hashed key.
• hash = hashfunc(key)
index = hash % array_size
Advantages
• The main advantage of hash tables over other table data structures
is speed.
• This advantage is more apparent when the number of entries is large
(thousands or more).
• Hash tables are particularly efficient when the maximum number of
entries can be predicted in advance, so that the bucket
array can be allocated once with the optimum size and never resized.
Hash function
• A hash function is any function that can be used to map a data set
of an arbitrary size to a data set of a fixed size, which falls into the hash
table.
• The values returned by a hash function are called hash values, hash codes,
hash sums, or simply hashes.
Continue…
• A hash function is any function that can be used to map
a data set of an arbitrary size to a data set of a fixed
size, which falls into the hash table.
• The values returned by a hash function are called hash
values, hash codes, hash sums, or simply hashes.
• To achieve a good hashing mechanism, It is important to have
a good hash function with the following basic requirements:
• Easy to compute
• Uniform distribution
• Less Collision
Hash Table
• A hash table is a data structure that is used to store keys/value pairs. It
uses a hash function to compute an index into an array in which an
element will be inserted or searched.
• By using a good hash function, hashing can work well. Under reasonable
assumptions, the average time required to search for an element in a hash
table is O(1).
Collision resolution techniques
• If x1 and x2 are two different keys, it is possible that h(x1) = h(x2). This
is called a collision. Collision resolution is the most important issue in
hash table implementations.
• Choosing a hash function that minimizes the number of collisions and
also hashes uniformly is another critical issue.
• Separate chaining (open hashing)
• Linear probing (open addressing or closed hashing)
• Quadratic Probing
• Double hashing
Separate Chaining (Open Hashing)
• Separate chaining is one of the most commonly used collision resolution
techniques.
• It is usually implemented using linked lists. In separate chaining, each
element of the hash table is a linked list.
• To store an element in the hash table you must insert it into a specific
linked list.
• If there is any collision (i.e. two different elements have same hash value)
then store both the elements in the same linked list.
Linear Probing
• In open addressing, instead of in linked lists, all entry records
are stored in the array itself.
• When a new entry has to be inserted, the hash index of the
hashed value is computed and then the array is examined
(starting with the hashed index).
• If the slot at the hashed index is unoccupied, then the entry
record is inserted in slot at the hashed index else it proceeds
in some probe sequence until it finds an unoccupied slot.
Continue…
• The probe sequence is the sequence that is followed while
traversing through entries. In different probe sequences, you can
have different intervals between successive entry slots or probes.
• When searching for an entry, the array is scanned in the same
sequence until either the target element is found or an unused slot
is found. This indicates that there is no such key in the table. The
name "open addressing" refers to the fact that the location or
address of the item is not determined by its hash value.
Continue…
• Linear probing is when the interval between successive probes is
fixed (usually to 1). Let’s assume that the hashed index for a
particular entry is index. The probing sequence for linear
probing will be:
index = index % hashTableSize
index = (index + 1) % hashTableSize
index = (index + 2) % hashTableSize
index = (index + 3) % hashTableSize
Quadratic Probing
• Quadratic probing is similar to linear probing and the only
difference is the interval between successive probes or entry
slots.
• Here, when the slot at a hashed index for an entry record is
already occupied, you must start traversing until you find an
unoccupied slot.
• The interval between slots is computed by adding the
successive value of an arbitrary polynomial in the original
hashed index.
Continue…
• Let us assume that the hashed index for an entry is index and
at index there is an occupied slot. The probe sequence will be as follows:
index = index % hashTableSize
index = (index + 12) % hashTableSize
index = (index + 22) % hashTableSize
index = (index + 32) % hashTableSize
Double hashing
• Double hashing is similar to linear probing and the only
difference is the interval between successive probes. Here, the
interval between probes is computed by using two hash
functions.
• Let us say that the hashed index for an entry record is an index
that is computed by one hashing function and the slot at that
index is already occupied. You must start traversing in a specific
probing sequence to look for an unoccupied slot. The probing
sequence will be:
Continue…
index = (index + 1 * indexH) % hashTableSize;
index = (index + 2 * indexH) % hashTableSize;
Applications
• Associative arrays: Hash tables are commonly used to implement many
types of in-memory tables. They are used to implement associative arrays
(arrays whose indices are arbitrary strings or other complicated objects).
• Database indexing: Hash tables may also be used as disk-based data
structures and database indices (such as in dbm).
• Caches: Hash tables can be used to implement caches i.e. auxiliary data
tables that are used to speed up the access to data, which is primarily stored
in slower media.
• Object representation: Several dynamic languages, such as Perl, Python,
JavaScript, and Ruby use hash tables to implement objects.
• Hash Functions are used in various algorithms to make their computing
faster.
References
• https://www.hackerearth.com/practice/data-structures/hash-tables/basics-
of-hash-tables/tutorial/

More Related Content

What's hot

heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
rajshreemuthiah
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Arrays
ArraysArrays
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Hashing
HashingHashing
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
Ashish Arun
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
Himanshu Kesharwani
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
sagar yadav
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
FarihaHabib123
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Sorting
SortingSorting
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 

What's hot (20)

heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Linked list
Linked listLinked list
Linked list
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Arrays
ArraysArrays
Arrays
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Hashing
HashingHashing
Hashing
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
Heaps
HeapsHeaps
Heaps
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Sorting
SortingSorting
Sorting
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 

Similar to Hashing

Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
Chinmaya M. N
 
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae javahashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
ishasharma835109
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
DADITIRUMALATARUN
 
Ts project Hash based inventory system
Ts project Hash based inventory systemTs project Hash based inventory system
Ts project Hash based inventory system
DADITIRUMALATARUN
 
Hashing
HashingHashing
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
BabaShaikh3
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptx
my6305874
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
Jawad Khan
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
AgonySingh
 
linear probing
linear probinglinear probing
linear probing
rajshreemuthiah
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
Dr.Shweta
 
Hashing
HashingHashing
Hashing
LavanyaJ28
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm
farhankhan89766
 
Data Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table pptData Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table ppt
JUSTFUN40
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
Akhil Prem
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
skilljiolms
 

Similar to Hashing (20)

Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 
hashing in data strutures advanced in languae java
hashing in data strutures advanced in languae javahashing in data strutures advanced in languae java
hashing in data strutures advanced in languae java
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
 
Ts project Hash based inventory system
Ts project Hash based inventory systemTs project Hash based inventory system
Ts project Hash based inventory system
 
Hashing
HashingHashing
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
 
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
 
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
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
 
Hash table
Hash tableHash table
Hash table
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
linear probing
linear probinglinear probing
linear probing
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
 
Hash pre
Hash preHash pre
Hash pre
 
asdfew.pptx
asdfew.pptxasdfew.pptx
asdfew.pptx
 
Hashing
HashingHashing
Hashing
 
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
 
Data Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table pptData Structure and Algorithms: What is Hash Table ppt
Data Structure and Algorithms: What is Hash Table ppt
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
 

More from Amar Jukuntla

Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
Types of files
Types of filesTypes of files
Types of files
Amar Jukuntla
 
Unit 2
Unit 2Unit 2
Problem Solving
Problem Solving Problem Solving
Problem Solving
Amar Jukuntla
 
Intelligent Agents
Intelligent Agents Intelligent Agents
Intelligent Agents
Amar Jukuntla
 
Introduction
IntroductionIntroduction
Introduction
Amar Jukuntla
 
Sorting
SortingSorting
Sorting
Amar Jukuntla
 
Sorting
SortingSorting
Sorting
Amar Jukuntla
 
Nature of open source
Nature of open sourceNature of open source
Nature of open source
Amar Jukuntla
 
Linux Directory System: Introduction
Linux Directory System: IntroductionLinux Directory System: Introduction
Linux Directory System: Introduction
Amar Jukuntla
 
Introduction to Data Structures
Introduction to Data StructuresIntroduction to Data Structures
Introduction to Data Structures
Amar Jukuntla
 
Learning
LearningLearning
Learning
Amar Jukuntla
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
Amar Jukuntla
 
First Order Logic
First Order LogicFirst Order Logic
First Order Logic
Amar Jukuntla
 
A*
A*A*
Agents1
Agents1Agents1
Agents1
Amar Jukuntla
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
Amar Jukuntla
 

More from Amar Jukuntla (19)

Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Types of files
Types of filesTypes of files
Types of files
 
Planning
Planning Planning
Planning
 
Unit 2
Unit 2Unit 2
Unit 2
 
Problem Solving
Problem Solving Problem Solving
Problem Solving
 
Intelligent Agents
Intelligent Agents Intelligent Agents
Intelligent Agents
 
Introduction
IntroductionIntroduction
Introduction
 
DFS
DFSDFS
DFS
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Nature of open source
Nature of open sourceNature of open source
Nature of open source
 
Linux Directory System: Introduction
Linux Directory System: IntroductionLinux Directory System: Introduction
Linux Directory System: Introduction
 
Introduction to Data Structures
Introduction to Data StructuresIntroduction to Data Structures
Introduction to Data Structures
 
Learning
LearningLearning
Learning
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
 
First Order Logic
First Order LogicFirst Order Logic
First Order Logic
 
A*
A*A*
A*
 
Agents1
Agents1Agents1
Agents1
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 

Recently uploaded

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 

Recently uploaded (20)

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 

Hashing

  • 2. Index • Introduction • Advantages • Hash Function • Hash Table • Collision Resolution Techniques • Separate Chaining • Linear Chaining • Quadratic Probing • Double Hashing • Application • Reference
  • 3. Introduction • Hashing is a technique that is used to uniquely identify a specific object from a group of similar objects. • Some examples of how hashing is used in our lives include: • In universities, each student is assigned a unique roll number that can be used to retrieve information about them. • In libraries, each book is assigned a unique number that can be used to determine information about the book, such as its exact position in the library or the users it has been issued to etc. • In both these examples the students and books were hashed to a unique number.
  • 4. Continue… • Assume that you have an object and you want to assign a key to it to make searching easy. To store the key/value pair, you can use a simple array like a data structure where keys (integers) can be used directly as an index to store values. However, in cases where the keys are large and cannot be used directly as an index, you should use hashing.
  • 5. Continue… • In hashing, large keys are converted into small keys by using hash functions. • The values are then stored in a data structure called hash table. • The idea of hashing is to distribute entries (key/value pairs) uniformly across an array. • Each element is assigned a key (converted key). • By using that key you can access the element in O(1) time. Using the key, the algorithm (hash function) computes an index that suggests where an entry can be found or inserted.
  • 6. Continue… • Hashing is implemented in two steps: • An element is converted into an integer by using a hash function. This element can be used as an index to store the original element, which falls into the hash table. • The element is stored in the hash table where it can be quickly retrieved using hashed key. • hash = hashfunc(key) index = hash % array_size
  • 7. Advantages • The main advantage of hash tables over other table data structures is speed. • This advantage is more apparent when the number of entries is large (thousands or more). • Hash tables are particularly efficient when the maximum number of entries can be predicted in advance, so that the bucket array can be allocated once with the optimum size and never resized.
  • 8. Hash function • A hash function is any function that can be used to map a data set of an arbitrary size to a data set of a fixed size, which falls into the hash table. • The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes.
  • 9. Continue… • A hash function is any function that can be used to map a data set of an arbitrary size to a data set of a fixed size, which falls into the hash table. • The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes. • To achieve a good hashing mechanism, It is important to have a good hash function with the following basic requirements: • Easy to compute • Uniform distribution • Less Collision
  • 10. Hash Table • A hash table is a data structure that is used to store keys/value pairs. It uses a hash function to compute an index into an array in which an element will be inserted or searched. • By using a good hash function, hashing can work well. Under reasonable assumptions, the average time required to search for an element in a hash table is O(1).
  • 11. Collision resolution techniques • If x1 and x2 are two different keys, it is possible that h(x1) = h(x2). This is called a collision. Collision resolution is the most important issue in hash table implementations. • Choosing a hash function that minimizes the number of collisions and also hashes uniformly is another critical issue. • Separate chaining (open hashing) • Linear probing (open addressing or closed hashing) • Quadratic Probing • Double hashing
  • 12. Separate Chaining (Open Hashing) • Separate chaining is one of the most commonly used collision resolution techniques. • It is usually implemented using linked lists. In separate chaining, each element of the hash table is a linked list. • To store an element in the hash table you must insert it into a specific linked list. • If there is any collision (i.e. two different elements have same hash value) then store both the elements in the same linked list.
  • 13.
  • 14. Linear Probing • In open addressing, instead of in linked lists, all entry records are stored in the array itself. • When a new entry has to be inserted, the hash index of the hashed value is computed and then the array is examined (starting with the hashed index). • If the slot at the hashed index is unoccupied, then the entry record is inserted in slot at the hashed index else it proceeds in some probe sequence until it finds an unoccupied slot.
  • 15. Continue… • The probe sequence is the sequence that is followed while traversing through entries. In different probe sequences, you can have different intervals between successive entry slots or probes. • When searching for an entry, the array is scanned in the same sequence until either the target element is found or an unused slot is found. This indicates that there is no such key in the table. The name "open addressing" refers to the fact that the location or address of the item is not determined by its hash value.
  • 16. Continue… • Linear probing is when the interval between successive probes is fixed (usually to 1). Let’s assume that the hashed index for a particular entry is index. The probing sequence for linear probing will be: index = index % hashTableSize index = (index + 1) % hashTableSize index = (index + 2) % hashTableSize index = (index + 3) % hashTableSize
  • 17. Quadratic Probing • Quadratic probing is similar to linear probing and the only difference is the interval between successive probes or entry slots. • Here, when the slot at a hashed index for an entry record is already occupied, you must start traversing until you find an unoccupied slot. • The interval between slots is computed by adding the successive value of an arbitrary polynomial in the original hashed index.
  • 18. Continue… • Let us assume that the hashed index for an entry is index and at index there is an occupied slot. The probe sequence will be as follows: index = index % hashTableSize index = (index + 12) % hashTableSize index = (index + 22) % hashTableSize index = (index + 32) % hashTableSize
  • 19. Double hashing • Double hashing is similar to linear probing and the only difference is the interval between successive probes. Here, the interval between probes is computed by using two hash functions. • Let us say that the hashed index for an entry record is an index that is computed by one hashing function and the slot at that index is already occupied. You must start traversing in a specific probing sequence to look for an unoccupied slot. The probing sequence will be:
  • 20. Continue… index = (index + 1 * indexH) % hashTableSize; index = (index + 2 * indexH) % hashTableSize;
  • 21. Applications • Associative arrays: Hash tables are commonly used to implement many types of in-memory tables. They are used to implement associative arrays (arrays whose indices are arbitrary strings or other complicated objects). • Database indexing: Hash tables may also be used as disk-based data structures and database indices (such as in dbm). • Caches: Hash tables can be used to implement caches i.e. auxiliary data tables that are used to speed up the access to data, which is primarily stored in slower media. • Object representation: Several dynamic languages, such as Perl, Python, JavaScript, and Ruby use hash tables to implement objects. • Hash Functions are used in various algorithms to make their computing faster.