SlideShare a Scribd company logo
CSCE 3110
Data Structures & Algorithm
Analysis
Rada Mihalcea
http://www.cs.unt.edu/~rada/CSCE3110
Hashing
Reading: Chap.5, Weiss
Dictionaries stores elements so that they can be
located quickly using keys.
For eg
A Dictionary may hold bank accounts.
In which key will be account number.
And each account may stores many additional
information.
Dictionaries
How to Implement a Dictionary?
Different data structure to realize a key
Array , Linked list
Binary tree
Hash table
Red/Black tree
AVL Tree
B-Tree
Why Hashing??
The sequential search algorithm takes time
proportional to the data size, i.e, O(n).
Binary search improves on liner search reducing
the search time to O(log n).
With a BST, an O(log n) search efficiency can
be obtained; but the worst-case complexity is
O(n).
To guarantee the O(log n) search time, BST
height balancing is required ( i.e., AVL trees).
Why Hashing?? (Cntd.)
Suppose that we want to store 10,000 students records
(each with a 5-digit ID) in a given container.
· A linked list implementation would take O(n) time.
· A height balanced tree would give O(log n)
access time.
· Using an array of size 100,000 would give O(1)
access time but will lead to a lot of space wastage.
Why Hashing?? (Cntd.)
Is there some way that we could get O(1) access
without wasting a lot of space?
The answer is hashing.
Hashing
Another important and widely useful
technique for implementing dictionaries
Constant time per operation (on the average)
Like an array, come up with a function to map
the large range into one which we can
manage.
Basic Idea
Use hash function to map keys into positions
in a hash table
Ideally
If Student A has ID(Key) k and h is hash
function, then A’s Details is stored in position
h(k) of table
To search for A, compute h(k) to locate
position. If no element, dictionary does not
contain A.
Example
Let keys be ID of 100 students
And ID in form of like 345610.
Now, we decided to take A[100]
And, Hash function is , say , LAST TWO DIGIT
So, 103062 will go to location 62
And same if some one have 113062
Then again goes to the location 62
THIS EVENT IS CALLED COLLISION
Collision Resolution
Chaining
Linear Probe
Double hashing
Chaining
Hash Functions
A Good Hash function is one which distribute keys
evenly among the slots.
And It is said that Hash Function is more art than a
science. Becoz it need to analyze the data.
Key
Hash
Function Slot
Hash Function(cntd.)
Need of choose a good Hash function
Quick Compute.
Distributes keys in uniform manner throughout the
table.
How to deal with Hashing non integer Key???
1.Find some way of turning keys into integer.
eg if key is in character then convert it into integer using
ASCII
2.Then use standard Hash Function on the integer.
Hash Function (contd.)
Hash code map
Keys Integer
Compression map
Integer A[0….m-1]
The Mapping of keys to indices of a hash table is called a
hash function.
The Hash Function is ussually the composition of two
maps:
Collision Resolution (contd.)
Now, there is two more techniques to deal
with collision
Linear Probing
Double Hashing
Linear probe
Linearprobeinsert(k)
If(table is full)
{error}
probe =h(k)
while(table[probe] is occupied)
{probe = (probe + 1) % m //m is no. of slots
}
Table[probe]=k
Linear Probe(contd.)
If the current location is used, Try the next
table Location.
Used less memory than chaining as one does
not have to store all those link(i.e. address of
others).
Slower than chaining as one might have to
walk along the table for a long time.
Linear Probe (contd.)
Linear probe (contd.)
Deletion in Linear probe
Double Hashing
h1(k) - Position in the table where we first
check for the key
h2(k) – Determine offset when h1(k) is
already occupied
In Linear probing offset is always 1.
Double Hashing (contd.)
Doublehashing insert(k)
If (table is full)
{error
}
Probe=h1(k); offset=h2(k);
While (table[probe] is occupied)
{probe=(probe + offset)%m
}
table[probe]=k;
Double Hashing(contd.)
Double Hashing(contd.)
Double Hashing(contd.)
Double Hashing(contd.)
Double Hashing(contd.)
Double Hashing(contd.)
Double Hashing(contd.)
Double Hashing(contd.)
Thank
U 

More Related Content

PPT
Hash table
PPTX
Hashing Technique In Data Structures
PPTX
Hashing In Data Structure
PPT
Data Structure and Algorithms Hashing
PPT
PPT
Chapter 12 ds
PPTX
Hashing in datastructure
Hash table
Hashing Technique In Data Structures
Hashing In Data Structure
Data Structure and Algorithms Hashing
Chapter 12 ds
Hashing in datastructure

What's hot (20)

PPTX
Collision in Hashing.pptx
PPTX
Data structure - Graph
PPTX
Analysis of algorithm
PPT
Extensible hashing
PDF
Symbol table in compiler Design
PPTX
Bfs and Dfs
PPT
Binary search tree(bst)
PPTX
DATABASE CONSTRAINTS
PPT
b+ tree
PDF
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
PPT
Bubble sort
PPTX
Asymptotic Notation
PPT
Binary Search
PPT
Intermediate code generation (Compiler Design)
PPT
BINARY TREE REPRESENTATION.ppt
PDF
Syntax directed translation
PPTX
Linked list
PPTX
Recognition-of-tokens
PDF
Algorithms Lecture 1: Introduction to Algorithms
PPTX
Queue ppt
Collision in Hashing.pptx
Data structure - Graph
Analysis of algorithm
Extensible hashing
Symbol table in compiler Design
Bfs and Dfs
Binary search tree(bst)
DATABASE CONSTRAINTS
b+ tree
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
Bubble sort
Asymptotic Notation
Binary Search
Intermediate code generation (Compiler Design)
BINARY TREE REPRESENTATION.ppt
Syntax directed translation
Linked list
Recognition-of-tokens
Algorithms Lecture 1: Introduction to Algorithms
Queue ppt
Ad

Similar to Hashing PPT (20)

PPTX
hashing1.pptx Data Structures and Algorithms
PPTX
hashing in data strutures advanced in languae java
PPT
Hashing
PPTX
Lecture14_15_Hashing.pptx
PPTX
Presentation.pptx
PPTX
Introduction to Hash Tables | What is a HashTable in Algorithm
PPTX
Data Structures-Topic-Hashing, Collision
PDF
hashing.pdf
PPTX
Hashing And Hashing Tables
PDF
Hashing and File Structures in Data Structure.pdf
PPTX
Hashing a searching technique in data structures
PPTX
Hashing using a different methods of technic
PPT
Hashing in Data Structure and analysis of Algorithms
PPTX
8. Hash table
PPTX
hashing in data structure for engineering.pptx
PPTX
hashing in data structure for Btech .pptx
PPTX
Hashing
PPTX
hashing in data structure for Btech.pptx
PDF
Algorithms notes tutorials duniya
PPTX
session 15 hashing.pptx
hashing1.pptx Data Structures and Algorithms
hashing in data strutures advanced in languae java
Hashing
Lecture14_15_Hashing.pptx
Presentation.pptx
Introduction to Hash Tables | What is a HashTable in Algorithm
Data Structures-Topic-Hashing, Collision
hashing.pdf
Hashing And Hashing Tables
Hashing and File Structures in Data Structure.pdf
Hashing a searching technique in data structures
Hashing using a different methods of technic
Hashing in Data Structure and analysis of Algorithms
8. Hash table
hashing in data structure for engineering.pptx
hashing in data structure for Btech .pptx
Hashing
hashing in data structure for Btech.pptx
Algorithms notes tutorials duniya
session 15 hashing.pptx
Ad

Recently uploaded (20)

PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
assetexplorer- product-overview - presentation
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
history of c programming in notes for students .pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Autodesk AutoCAD Crack Free Download 2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Operating system designcfffgfgggggggvggggggggg
Salesforce Agentforce AI Implementation.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Nekopoi APK 2025 free lastest update
Complete Guide to Website Development in Malaysia for SMEs
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle Fusion HCM Cloud Demo for Beginners
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Odoo Companies in India – Driving Business Transformation.pdf
assetexplorer- product-overview - presentation
Download FL Studio Crack Latest version 2025 ?
history of c programming in notes for students .pptx
Design an Analysis of Algorithms II-SECS-1021-03

Hashing PPT

  • 1. CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea http://www.cs.unt.edu/~rada/CSCE3110 Hashing Reading: Chap.5, Weiss
  • 2. Dictionaries stores elements so that they can be located quickly using keys. For eg A Dictionary may hold bank accounts. In which key will be account number. And each account may stores many additional information. Dictionaries
  • 3. How to Implement a Dictionary? Different data structure to realize a key Array , Linked list Binary tree Hash table Red/Black tree AVL Tree B-Tree
  • 4. Why Hashing?? The sequential search algorithm takes time proportional to the data size, i.e, O(n). Binary search improves on liner search reducing the search time to O(log n). With a BST, an O(log n) search efficiency can be obtained; but the worst-case complexity is O(n). To guarantee the O(log n) search time, BST height balancing is required ( i.e., AVL trees).
  • 5. Why Hashing?? (Cntd.) Suppose that we want to store 10,000 students records (each with a 5-digit ID) in a given container. · A linked list implementation would take O(n) time. · A height balanced tree would give O(log n) access time. · Using an array of size 100,000 would give O(1) access time but will lead to a lot of space wastage.
  • 6. Why Hashing?? (Cntd.) Is there some way that we could get O(1) access without wasting a lot of space? The answer is hashing.
  • 7. Hashing Another important and widely useful technique for implementing dictionaries Constant time per operation (on the average) Like an array, come up with a function to map the large range into one which we can manage.
  • 8. Basic Idea Use hash function to map keys into positions in a hash table Ideally If Student A has ID(Key) k and h is hash function, then A’s Details is stored in position h(k) of table To search for A, compute h(k) to locate position. If no element, dictionary does not contain A.
  • 9. Example Let keys be ID of 100 students And ID in form of like 345610. Now, we decided to take A[100] And, Hash function is , say , LAST TWO DIGIT So, 103062 will go to location 62 And same if some one have 113062 Then again goes to the location 62 THIS EVENT IS CALLED COLLISION
  • 12. Hash Functions A Good Hash function is one which distribute keys evenly among the slots. And It is said that Hash Function is more art than a science. Becoz it need to analyze the data. Key Hash Function Slot
  • 13. Hash Function(cntd.) Need of choose a good Hash function Quick Compute. Distributes keys in uniform manner throughout the table. How to deal with Hashing non integer Key??? 1.Find some way of turning keys into integer. eg if key is in character then convert it into integer using ASCII 2.Then use standard Hash Function on the integer.
  • 14. Hash Function (contd.) Hash code map Keys Integer Compression map Integer A[0….m-1] The Mapping of keys to indices of a hash table is called a hash function. The Hash Function is ussually the composition of two maps:
  • 15. Collision Resolution (contd.) Now, there is two more techniques to deal with collision Linear Probing Double Hashing
  • 16. Linear probe Linearprobeinsert(k) If(table is full) {error} probe =h(k) while(table[probe] is occupied) {probe = (probe + 1) % m //m is no. of slots } Table[probe]=k
  • 17. Linear Probe(contd.) If the current location is used, Try the next table Location. Used less memory than chaining as one does not have to store all those link(i.e. address of others). Slower than chaining as one might have to walk along the table for a long time.
  • 20. Double Hashing h1(k) - Position in the table where we first check for the key h2(k) – Determine offset when h1(k) is already occupied In Linear probing offset is always 1.
  • 21. Double Hashing (contd.) Doublehashing insert(k) If (table is full) {error } Probe=h1(k); offset=h2(k); While (table[probe] is occupied) {probe=(probe + offset)%m } table[probe]=k;