0% found this document useful (0 votes)
17 views

Hash Table

A hash table stores key-value pairs by converting keys into indexes using a hash function. Collisions occur when different keys hash to the same index. Separate chaining handles collisions by storing keys that hash to the same index in a linked list at that index. For example, a hash table of size 7 storing keys 50, 700, 76, 85, 92, 73, 101 would handle collisions by inserting keys into linked lists at indexes 0, 4, and 6 respectively.

Uploaded by

eyman hamad
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Hash Table

A hash table stores key-value pairs by converting keys into indexes using a hash function. Collisions occur when different keys hash to the same index. Separate chaining handles collisions by storing keys that hash to the same index in a linked list at that index. For example, a hash table of size 7 storing keys 50, 700, 76, 85, 92, 73, 101 would handle collisions by inserting keys into linked lists at indexes 0, 4, and 6 respectively.

Uploaded by

eyman hamad
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

‫‪Hash table‬‬

‫ايمان حمد النيل‬


‫ايناس صالح‬
‫رنا مصطفى‬
What is hash table?
• Hashing is a technique to convert a range of key values into a
range of indexes of an array.
Example:
• Consider an example of hash table of size 20, and the
following items are to be stored. Item are in the (key,value)
format.
• (1,20) (2,70) (42,80) (4,25) (12,44)
Collision

When the two different values have the same value, then the
problem occurs between the two values, known as a collision
1. replacement
2. Open Hashing: It is also known as closed addressing.
• Linear probing
• Quadratic probing
1. Closed Hashing: It is also known as open addressing.
Replacement:
Open Hashing:
linear probing:
Open Hashing:
quadratic probing:
Closed Hashing: It is also known as open addressing.

• Separate Chaining : The idea behind separate chaining is to


implement the array as a linked list called a chain. Separate
chaining is one of the most popular and commonly used
techniques in order to handle collisions. he linked list data
structure is used to implement this technique. So what
happens is, when multiple elements are hashed into the same
slot index, then these elements are inserted into a singly-
linked list which is known as a chain.
Example:
• Let us consider a simple hash function as “key mod 7” and a
sequence of keys as 50, 700, 76, 85, 92, 73, 101:
Advantages:
• Simple to implement. Hash table never fills up, we can always
add more elements to the chain. Less sensitive to the hash
function or load factors. It is mostly used when it is unknown
how many and how frequently keys may be inserted or
deleted. Disadvantages: The 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. Wastage of Space (Some Parts of the
hash table are never used) If the chain becomes long, then
search time can become O(n) in the worst caseUses extra
space for links
Hashing operation:
Display:

You might also like