0% found this document useful (0 votes)
15 views3 pages

Hashing (Omar Sakr)

Uploaded by

1mohamed.gamal54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Hashing (Omar Sakr)

Uploaded by

1mohamed.gamal54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Hashing in Data Structure

What Is Hashing?
Hashing is a method that converts input of any length into a fixed-size value (called a hash)
using a hash function, and then uses that hash as an index into a hash table for fast data access

Why we Use Hashing?


Key-value support: Hashing is ideal for implementing key-value data structures.
Fast data retrieval: Hashing allows for quick access to elements with constant-time complexity.
Efficiency: Insertion, deletion, and searching operations are highly efficient.
Low memory usage: uses less memory as it allocates a fixed space for storing elements.
Scalability: Hashing performs well with large data sets, maintaining constant access time.
Security and encryption: Hashing is essential for secure data storage and integrity verification.
To learn more about Hashing Please refer to the Introduction to Hashing – Data Structure and
Algorithm Tutorials
Components of Hashing
1. Key: A Key can be anything string or integer which is fed as input in the hash function
the technique that determines an index or location for storage of an item in a data
structure.
2. Hash Function: Receives the input key and returns the index of an element in an array
called a hash table. The index is known as the hash index.
3. Hash Table: Hash table is typically an array of lists. It stores values corresponding to the
keys. where each data value has its own unique index.

Provided from “geeksforgeeks”


Advanced Hashing Concepts & Variations
1. Load Factor: Ratio of stored elements to table size. High load can degrade performance;
careful resizing is needed.
2. Dynamic Hashing – Linear Hashing: Automatically expands or shrinks buckets based on
load without full rehashing.
3. Cryptographic Hash Functions: Used in security
4. One-way, deterministic, with strong collision and pre-image resistance.
5. Applications include data integrity, digital signatures, secure password storage,
blockchain.

How does Hashing work?


Suppose we have a set of strings {“ab”, “cd”, “fg”} and we would like to store it in a table.
We take the ASCII codes of the characters and sum them.
-“ab” = 97+98=195 -“cd” =99+100=199 -“fg” =102+103=205.
Then with table size 7, use hash = sum % 7 →

195 % 7 = 6 → “ab” at index 6,

199 % 7 = 3 → “cd” at index 3,

205 % 7 = 3 → “fg” also at index 3 → collision with “cd”.

key Value
1
2
3 “cd”: “fg” collision
4
5
6 “ab”
7
What is Collision in Hashing?
When two or more keys have the same hash value, a collision happens. If we consider
the above example, the hash function we used is the sum of the letters, but if we examined the
hash function closely then the problem can be easily visualized that for different strings same
hash value is being generated by the hash function. To handle this collision, we use Collision
Resolution Techniques.

Collision Resolution Techniques


There are many methods to handle collision, but we will take the two mainly methods:
1. Separate Chaining
The idea behind Separate Chaining is to make each cell of the hash table point to a
linked list of records that have the same hash function value. Chaining is simple but
requires additional memory outside the table.

Provided from “geeksforgeeks”


2. Open Addressing
all elements are stored in the hash table itself. Each table entry contains a record
When searching for an element, we examine the table slots one by one until the desired
element is found or it is clear that the element is not in the table.

Provided from “geeksforgeeks”

You might also like