Hash Tables Linear Probing and Double Hashing

  • Thread starter lina29
  • Start date
  • Tags
    Linear
In summary, the hash table has 11 entries and the hash function h(x) = x mod 11. The result of hashing the keys 10,16,11,43,33,13,14,12,3, and 22, assuming collisions are handled by open addressing with linear probing is 10,5,2,0,1,2,3,4,5,6,7,8.
  • #1
lina29
85
0

Homework Statement


Consider a hash table T with 11 entries and the hash function h(x) = x mod 11. Show the result of hashing the keys 10,16,11,43,33,13,14,12,3, and 22, assuming collisions are handled by
(a) open addressing with linear probing
(b) double hashing using a secondary hash function h′(x) = 5−(x mod 5)


Homework Equations





The Attempt at a Solution



I believe I have the correct answer, I just want to double-check since I'm having difficulties.

Using a table I have:
Key ---- h(x) ---- h'(x) ---- probes LP ---- probes DH
10 ---- 10 ---- ---- 10 ---- 10
16 ---- 05 ---- ---- 5 ---- 5
11 ---- 00 ---- ---- 0 ---- 0
43 ---- 10 ---- 2 ---- 10, 0, 1 ---- 10,2
33 ---- 00 ---- 2 ---- 0, 1, 2 ---- 0, 2, 3
13 ---- 02 ---- 2 ---- 2,3 ---- 2,2,3,4
14 ---- 03 ---- 1 ---- 3,4 ---- 3,1
12 ---- 01 ---- 3 ---- 1,2,3,4,5,6 ---- 1,3,4,5,6
03 ---- 03 ---- 2 ---- 3,4,5,6,7 ---- 3,2,3,4,5,6,7
22 ---- 00 ---- 3 ---- 0,1,2,3,4,5,6,7,8 ---- 0,3,4,5,6,7,8
 
Physics news on Phys.org
  • #2
The linear probe interval isn't specified. Are you supposed to assume it's 1? The contents of the hash table is not specified, so how are you supposed to know when collisions have occurred, or are you just supposed to list a set of indexes for the collision sequence for each key, or are you supposed to assume that the hash table is initially empty and the list of keys you're given are going to be stored in the hash table in the listed key order?
 
  • #3
We're supposed to assume the interval is 1. I'm not sure I understand what you mean but you know a collision occurs when both keys have the same h(x) like keys 10 and 43 both have h(x) as 10
 
  • #4
lina29 said:
We're supposed to assume the interval is 1. I'm not sure I understand what you mean but you know a collision occurs when both keys have the same h(x) like keys 10 and 43 both have h(x) as 10
I understand that, but are you just supposed to list the order in probes would take place if the hash table was completely filled (no empty slots), or are you supposed to list the probes that would take place if the hash table was initially empty and you stored that list of 10 keys into the hash table, leaving one empty slot when done?
 
Last edited:
  • #5
We're supposed to list the probes by the place is should initially be at. if that spot is filled then we advance to the next spot until we find an empty spot
 
  • #6
Looks like it's the case where you're adding those 10 keys in order to an initially empty table, in which case your answer appears to be correct. Note, you can put [ code ] and [ /code ] (without the spaces) around your text to preserve it's format.
 
  • #7
thank you!
 

1. What is the purpose of using a hash table?

A hash table is a data structure that allows for efficient storage and retrieval of data. It uses a hashing function to map data to an index in an array, making it faster to search for and access data compared to other data structures like arrays or linked lists.

2. What is linear probing in hash tables?

Linear probing is a collision resolution technique used in hash tables. When there is a collision (i.e. multiple elements are mapped to the same index), linear probing searches for the next available empty index in the array and stores the element there. This can cause clustering and decrease the efficiency of the hash table.

3. How does double hashing work?

Double hashing is another collision resolution technique used in hash tables. It uses two different hashing functions to determine the next available index when there is a collision. The first hashing function is used to find the initial index, and the second hashing function is used to calculate the offset (i.e. the number of steps to take) to the next available index. This can help reduce clustering and improve the efficiency of the hash table.

4. What are the advantages of using hash tables over other data structures?

Hash tables offer fast search and retrieval operations, making them efficient for storing large amounts of data. They also have a constant time complexity for insertion, deletion, and lookup operations, regardless of the size of the data set. Additionally, they can handle a wide range of data types and are flexible in terms of resizing.

5. Can you explain the concept of load factor in hash tables?

The load factor of a hash table is the ratio of the number of elements stored in the hash table to the total number of buckets (or indices) in the hash table. A high load factor can lead to more collisions, which can decrease the efficiency of the hash table. Therefore, it is important to resize the hash table when the load factor becomes too high to maintain optimal performance.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
996
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
874
  • Nuclear Engineering
Replies
7
Views
559
Replies
58
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
9
Views
3K
  • General Math
2
Replies
51
Views
2K
  • General Math
Replies
24
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
Back
Top