PPT: Hashing | Algorithms - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


H a s h i n g
Page 2


H a s h i n g
Introduction
Hashing is a powerful technique that maps data to fixed-size 
indices using a hash function. This enables fast data 
operations with O(1) average time complexity.
Hashing uses a hash function to map data to fixed-size indices 
in a hash table. This enables fast data operations with O(1) 
average time complexity.
Hashing is widely used in databases, caching, symbol tables, 
and password storage due to its efficient O(1) average time 
complexity.
Page 3


H a s h i n g
Introduction
Hashing is a powerful technique that maps data to fixed-size 
indices using a hash function. This enables fast data 
operations with O(1) average time complexity.
Hashing uses a hash function to map data to fixed-size indices 
in a hash table. This enables fast data operations with O(1) 
average time complexity.
Hashing is widely used in databases, caching, symbol tables, 
and password storage due to its efficient O(1) average time 
complexity.
Hash Table
Structure
An array of size m (table 
size) where each slot 
stores a key-value pair or a 
linked list for handling 
collisions.
Insert
Add a key-value pair to the 
table by computing the 
hash and placing the data 
at the corresponding 
index.
Search
Retrieve a value for a given 
key by computing its hash 
and accessing the 
corresponding table 
position.
Delete
Remove a key-value pair 
from the table by finding 
its position and marking it 
as deleted or removing it.
With a good hash function, hash tables provide average-case O(1) time complexity for insert, search, and delete 
operations. In the worst case, these operations may degrade to O(n) if many collisions occur. For example, with a 
table size of 10, inserting key 23 would place it at index h(23) = 23 mod 10 = 3.
Page 4


H a s h i n g
Introduction
Hashing is a powerful technique that maps data to fixed-size 
indices using a hash function. This enables fast data 
operations with O(1) average time complexity.
Hashing uses a hash function to map data to fixed-size indices 
in a hash table. This enables fast data operations with O(1) 
average time complexity.
Hashing is widely used in databases, caching, symbol tables, 
and password storage due to its efficient O(1) average time 
complexity.
Hash Table
Structure
An array of size m (table 
size) where each slot 
stores a key-value pair or a 
linked list for handling 
collisions.
Insert
Add a key-value pair to the 
table by computing the 
hash and placing the data 
at the corresponding 
index.
Search
Retrieve a value for a given 
key by computing its hash 
and accessing the 
corresponding table 
position.
Delete
Remove a key-value pair 
from the table by finding 
its position and marking it 
as deleted or removing it.
With a good hash function, hash tables provide average-case O(1) time complexity for insert, search, and delete 
operations. In the worst case, these operations may degrade to O(n) if many collisions occur. For example, with a 
table size of 10, inserting key 23 would place it at index h(23) = 23 mod 10 = 3.
Collisions in Hashing
Definition
Collisions occur when two or more distinct keys map to 
the same index in the hash table. For example, both 23 
and 33 hash to index 3 when using h(k) = k mod 10.
These collisions are inevitable due to the pigeonhole 
principle 3 when mapping a larger set of possible keys 
to a smaller set of indices, some keys must share the 
same index.
Resolution Techniques
Separate Chaining: Store multiple keys in a linked list 
at the same index, allowing unlimited entries per slot.
Open Addressing: Find alternative slots in the table 
using probing sequences when a collision occurs.
The impact of collisions can significantly degrade hash table performance if not handled properly. The key goal in 
hash table design is to minimize collisions through good hash function selection and implement efficient 
resolution techniques.
Page 5


H a s h i n g
Introduction
Hashing is a powerful technique that maps data to fixed-size 
indices using a hash function. This enables fast data 
operations with O(1) average time complexity.
Hashing uses a hash function to map data to fixed-size indices 
in a hash table. This enables fast data operations with O(1) 
average time complexity.
Hashing is widely used in databases, caching, symbol tables, 
and password storage due to its efficient O(1) average time 
complexity.
Hash Table
Structure
An array of size m (table 
size) where each slot 
stores a key-value pair or a 
linked list for handling 
collisions.
Insert
Add a key-value pair to the 
table by computing the 
hash and placing the data 
at the corresponding 
index.
Search
Retrieve a value for a given 
key by computing its hash 
and accessing the 
corresponding table 
position.
Delete
Remove a key-value pair 
from the table by finding 
its position and marking it 
as deleted or removing it.
With a good hash function, hash tables provide average-case O(1) time complexity for insert, search, and delete 
operations. In the worst case, these operations may degrade to O(n) if many collisions occur. For example, with a 
table size of 10, inserting key 23 would place it at index h(23) = 23 mod 10 = 3.
Collisions in Hashing
Definition
Collisions occur when two or more distinct keys map to 
the same index in the hash table. For example, both 23 
and 33 hash to index 3 when using h(k) = k mod 10.
These collisions are inevitable due to the pigeonhole 
principle 3 when mapping a larger set of possible keys 
to a smaller set of indices, some keys must share the 
same index.
Resolution Techniques
Separate Chaining: Store multiple keys in a linked list 
at the same index, allowing unlimited entries per slot.
Open Addressing: Find alternative slots in the table 
using probing sequences when a collision occurs.
The impact of collisions can significantly degrade hash table performance if not handled properly. The key goal in 
hash table design is to minimize collisions through good hash function selection and implement efficient 
resolution techniques.
Separate Chaining
Implementation
Each slot in the hash table contains a linked list that stores all keys hashing to that index. This approach allows multiple keys 
to coexist at the same index position.
Operations
When inserting, the key-value pair is appended to the linked list at h(key). Searching requires traversing the linked list at 
h(key) to find the target key. Deletion involves removing the key from its linked list.
Example
With table size = 5 and h(k) = k mod 5, inserting 10, 15, and 20 would place all three in a linked list at index 0 (10³15³20), as 
they all hash to the same value.
Separate chaining offers advantages like simple implementation and no limit on collisions, but requires extra memory for linked 
lists and suffers from poor cache performance due to pointer chasing.
Read More
81 videos|113 docs|33 tests

FAQs on PPT: Hashing - Algorithms - Computer Science Engineering (CSE)

1. What is hashing and how does it work?
Ans.Hashing is a process that transforms input data of any size into a fixed-size string of characters, which is typically a sequence of numbers and letters. This transformation is achieved using a hashing algorithm. The output, known as a hash value or hash code, acts as a unique identifier for the input data. Hashing is commonly used in data structures like hash tables, as well as for securing passwords and ensuring data integrity.
2. What are the common applications of hashing?
Ans.Hashing has several important applications. It is widely used in data retrieval systems, such as hash tables, where it allows for efficient data access. In cybersecurity, hashing is utilized for password storage, ensuring that sensitive information is not stored in plain text. Additionally, hashing is essential in data integrity checks, digital signatures, and verifying file authenticity, as it allows for easy detection of changes or corruption in data.
3. What is the difference between a cryptographic hash function and a non-cryptographic hash function?
Ans.Cryptographic hash functions are designed to be secure against various types of attacks and are used in security applications, such as digital signatures and certificate verification. They must exhibit properties such as pre-image resistance and collision resistance. Non-cryptographic hash functions, on the other hand, are optimized for speed and performance rather than security. They are commonly used in applications like hash tables and checksums but may not be suitable for secure data processing.
4. What are some popular hashing algorithms?
Ans.Some widely used hashing algorithms include MD5, SHA-1, and SHA-256. MD5 produces a 128-bit hash value and was once popular for checksums, but it is now considered insecure for cryptographic purposes. SHA-1 generates a 160-bit hash and also faces vulnerabilities. SHA-256, part of the SHA-2 family, offers a 256-bit hash size and is currently recommended for secure applications due to its stronger security properties.
5. How does hashing ensure data integrity?
Ans.Hashing ensures data integrity by generating a unique hash value for a given set of data. When the data is modified, even slightly, the hash value changes significantly. This property allows users to compare hash values before and after data transmission or storage. If the hash values are different, it indicates that the data has been altered or corrupted, thereby providing a reliable method for verifying the integrity of data over time.
Related Searches

Semester Notes

,

study material

,

Important questions

,

PPT: Hashing | Algorithms - Computer Science Engineering (CSE)

,

Sample Paper

,

Viva Questions

,

Free

,

Extra Questions

,

PPT: Hashing | Algorithms - Computer Science Engineering (CSE)

,

shortcuts and tricks

,

mock tests for examination

,

Exam

,

ppt

,

past year papers

,

Summary

,

video lectures

,

Previous Year Questions with Solutions

,

practice quizzes

,

MCQs

,

PPT: Hashing | Algorithms - Computer Science Engineering (CSE)

,

pdf

,

Objective type Questions

;