SlideShare a Scribd company logo
1 of 34
HASHING
DEFN.,
 Hashing in the data structure is a technique of
mapping a large chunk of data into small
tables using a hashing function.
 It is also known as the message digest function.
 It is a technique that uniquely identifies a specific
item from a collection of similar items
HASH FUNCTION
 A hash function is a function that takes a set of
inputs of any arbitrary size and fits them into a
table or other data structure that contains fixed-
size elements.
 The table or data structure generated is usually
called a hash table.
SEPARATE CHAINING/OPEN HASHING
 To handle the collision,
 This technique creates a linked list to the slot for
which collision occurs.
 The new key is then inserted in the linked list.
 These linked lists to the slots appear like chains.
 That is why, this technique is called as separate
chaining.
 Advantages:
1) Simple to implement.
2) Hash table never fills up, we can always add more
elements to the chain.
3) Less sensitive to the hash function or load factors.
4) It is mostly used when it is unknown how many and
how frequently keys may be inserted or deleted.
 Disadvantages:
1) Cache performance of chaining is not good as keys
are stored using a linked list. Open addressing provides
better cache performance as everything is stored in the
same table.
2) Wastage of Space (Some Parts of hash table are
never used)
3) If the chain becomes long, then search time can
become O(n) in the worst case.
4) Uses extra space for links.
DISADVANTAGE OF SEPARATE CHAINING
OPEN ADDRESSING/CLOSED HASHING
LINEAR PROBING
 Linear probing is a scheme in computer
programming for resolving collisions in hash
tables, data structures for maintaining a collection
of key–value pairs and looking up the value
associated with a given key.
 In these schemes, each cell of a hash table stores
a single key–value pair.
 h´(𝑥) = 𝑥 𝑚𝑜𝑑 𝑚
 ℎ(𝑥, 𝑖) = (ℎ´(𝑥) + 𝑖)𝑚𝑜𝑑 𝑚
 The value of i| = 0, 1, . . ., m – 1. So we start from i
= 0
DRAWBACKS OF LINEAR PROBING
QUADRATIC PROBING
 Quadratic probing operates by taking the original
hash index and adding successive values of an
arbitrary quadratic polynomial until an open slot is
found.
 h´ = (𝑥) = 𝑥 𝑚𝑜𝑑 𝑚
 ℎ(𝑥, 𝑖) = (ℎ´(𝑥) + 𝑖2)𝑚𝑜𝑑 𝑚
 We can put some other quadratic equations also
using some constants
 The value of i = 0, 1, . . ., m – 1. So we start from i =
0, and increase this until we get one free space.
PROPERTIES OF QUADRATIC PROBING
DOUBLE HASHING
 Double hashing uses the idea of applying a second
hash function to key when a collision occurs. is size
of hash table.
 First hash function is typically
 hash1(key) = key % TABLE_SIZE
 A popular second hash function is :
 hash2(key) = PRIME – (key % PRIME) where
PRIME is a prime smaller than the TABLE_SIZE.
REHASHING
 Rehashing is the process of re-calculating the
hashcode of already stored entries (Key-Value
pairs), to move them to another bigger size
hashmap when the threshold is reached/crossed.
Rehashing of a hash map is done when the number
of elements in the map reaches the maximum
threshold value.
EXTENDIBLE HASING
 Extendible hashing is a dynamically updateable
disk-based index structure which implements a
hashing scheme utilizing a directory.
 The index is used to support exact match queries,
i.e., find the record with a given key.
 Overflows are handled by doubling the directory
which logically doubles the number of buckets.
CONTENT BEYOND SYLLABUS
 RED BLACK TREES
Red Black Tree is a Binary Search Tree in which every node is
colored either RED or BLACK.
 Rules That Every Red-Black Tree Follows:
 Every node has a colour either red or black.
 The root of the tree is always black.
 There are no two adjacent red nodes (A red node cannot have
a red parent or red child).
 Every path from a node (including root) to any of its
descendants NULL nodes has the same number of black
nodes.
 http://www.btechsmartclass.com/data_structures/red-black-
trees.html
 THANK YOU !

More Related Content

What's hot

What's hot (20)

Hashing
HashingHashing
Hashing
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Hashing data
Hashing dataHashing data
Hashing data
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Hashing
HashingHashing
Hashing
 
Analysis Of Algorithms - Hashing
Analysis Of Algorithms - HashingAnalysis Of Algorithms - Hashing
Analysis Of Algorithms - Hashing
 
Hashing
HashingHashing
Hashing
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
 
Searching
SearchingSearching
Searching
 
Hash table
Hash tableHash table
Hash table
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
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]
 
Selection sort
Selection sortSelection sort
Selection sort
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletion
 

Similar to Hashing

Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashing
Haripritha
 
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Subhajit Sahu
 
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
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
Bianca Teşilă
 
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdfAssignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
kksrivastava1
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
Rafi Dar
 

Similar to Hashing (20)

linear probing
linear probinglinear probing
linear probing
 
DS THEORY 35.pptx
DS THEORY 35.pptxDS THEORY 35.pptx
DS THEORY 35.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Hash pre
Hash preHash pre
Hash pre
 
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 and separate chain
Hashing and separate chainHashing and separate chain
Hashing and separate chain
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
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
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashing
 
Hashing And Hashing Tables
Hashing And Hashing TablesHashing And Hashing Tables
Hashing And Hashing Tables
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
 
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
Concurrent Hashing and Natural Parallelism : The Art of Multiprocessor Progra...
 
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
 
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
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
 
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdfAssignment4 Assignment 4 Hashtables In this assignment we w.pdf
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
 
asdfew.pptx
asdfew.pptxasdfew.pptx
asdfew.pptx
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
 

More from LavanyaJ28 (16)

Cs1301 syllabus
Cs1301  syllabusCs1301  syllabus
Cs1301 syllabus
 
Ds important questions
Ds important questionsDs important questions
Ds important questions
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
Graphs
GraphsGraphs
Graphs
 
Unit 3 trees
Unit 3   treesUnit 3   trees
Unit 3 trees
 
Heap types & Trees
Heap types & TreesHeap types & Trees
Heap types & Trees
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
 
Unit 1 Basic concepts to DS
Unit 1 Basic concepts to DSUnit 1 Basic concepts to DS
Unit 1 Basic concepts to DS
 
Unit 1 array based implementation
Unit 1  array based implementationUnit 1  array based implementation
Unit 1 array based implementation
 
Unit 1 polynomial manipulation
Unit 1   polynomial manipulationUnit 1   polynomial manipulation
Unit 1 polynomial manipulation
 
Unit 1 abstract data types
Unit 1 abstract data typesUnit 1 abstract data types
Unit 1 abstract data types
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 

Hashing

  • 2. DEFN.,  Hashing in the data structure is a technique of mapping a large chunk of data into small tables using a hashing function.  It is also known as the message digest function.  It is a technique that uniquely identifies a specific item from a collection of similar items
  • 3.
  • 4. HASH FUNCTION  A hash function is a function that takes a set of inputs of any arbitrary size and fits them into a table or other data structure that contains fixed- size elements.  The table or data structure generated is usually called a hash table.
  • 5.
  • 6. SEPARATE CHAINING/OPEN HASHING  To handle the collision,  This technique creates a linked list to the slot for which collision occurs.  The new key is then inserted in the linked list.  These linked lists to the slots appear like chains.  That is why, this technique is called as separate chaining.
  • 7.
  • 8.  Advantages: 1) Simple to implement. 2) Hash table never fills up, we can always add more elements to the chain. 3) Less sensitive to the hash function or load factors. 4) It is mostly used when it is unknown how many and how frequently keys may be inserted or deleted.  Disadvantages: 1) Cache performance of chaining is not good as keys are stored using a linked list. Open addressing provides better cache performance as everything is stored in the same table. 2) Wastage of Space (Some Parts of hash table are never used) 3) If the chain becomes long, then search time can become O(n) in the worst case. 4) Uses extra space for links.
  • 10. OPEN ADDRESSING/CLOSED HASHING LINEAR PROBING  Linear probing is a scheme in computer programming for resolving collisions in hash tables, data structures for maintaining a collection of key–value pairs and looking up the value associated with a given key.  In these schemes, each cell of a hash table stores a single key–value pair.  h´(𝑥) = 𝑥 𝑚𝑜𝑑 𝑚  ℎ(𝑥, 𝑖) = (ℎ´(𝑥) + 𝑖)𝑚𝑜𝑑 𝑚  The value of i| = 0, 1, . . ., m – 1. So we start from i = 0
  • 11.
  • 13. QUADRATIC PROBING  Quadratic probing operates by taking the original hash index and adding successive values of an arbitrary quadratic polynomial until an open slot is found.  h´ = (𝑥) = 𝑥 𝑚𝑜𝑑 𝑚  ℎ(𝑥, 𝑖) = (ℎ´(𝑥) + 𝑖2)𝑚𝑜𝑑 𝑚  We can put some other quadratic equations also using some constants  The value of i = 0, 1, . . ., m – 1. So we start from i = 0, and increase this until we get one free space.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 20.
  • 21. DOUBLE HASHING  Double hashing uses the idea of applying a second hash function to key when a collision occurs. is size of hash table.  First hash function is typically  hash1(key) = key % TABLE_SIZE  A popular second hash function is :  hash2(key) = PRIME – (key % PRIME) where PRIME is a prime smaller than the TABLE_SIZE.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. REHASHING  Rehashing is the process of re-calculating the hashcode of already stored entries (Key-Value pairs), to move them to another bigger size hashmap when the threshold is reached/crossed. Rehashing of a hash map is done when the number of elements in the map reaches the maximum threshold value.
  • 30.
  • 31.
  • 32. EXTENDIBLE HASING  Extendible hashing is a dynamically updateable disk-based index structure which implements a hashing scheme utilizing a directory.  The index is used to support exact match queries, i.e., find the record with a given key.  Overflows are handled by doubling the directory which logically doubles the number of buckets.
  • 33. CONTENT BEYOND SYLLABUS  RED BLACK TREES Red Black Tree is a Binary Search Tree in which every node is colored either RED or BLACK.  Rules That Every Red-Black Tree Follows:  Every node has a colour either red or black.  The root of the tree is always black.  There are no two adjacent red nodes (A red node cannot have a red parent or red child).  Every path from a node (including root) to any of its descendants NULL nodes has the same number of black nodes.  http://www.btechsmartclass.com/data_structures/red-black- trees.html