Question

In: Computer Science

Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key)...

Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key) = (16 - (key % 10)) + 1 to insert the following numbers into a dictionary's hash table: 1, 12, 14, 3, 5 and 17. The table size is 11. Show the table and where each value is inserted. No coding required for this problem.

Solutions

Expert Solution

Inserting 1
main hash value is 1
1 is inserted at position 1
-, 1, -, -, -, -, -, -, -, -, -

Inserting 12
main hash value is 1
There is already an item in 1
double hash value is 16
1 + 1*16 = 17
So, checking at index 17 % 11 = 6
12 is inserted at position 6
-, 1, -, -, -, -, 12, -, -, -, -

Inserting 14
main hash value is 3
14 is inserted at position 3
-, 1, -, 14, -, -, 12, -, -, -, -

Inserting 3
main hash value is 3
There is already an item in 3
double hash value is 16
3 + 1*16 = 19
So, checking at index 19 % 11 = 8
3 is inserted at position 8
-, 1, -, 14, -, -, 12, -, 3, -, -

Inserting 5
main hash value is 5
5 is inserted at position 5
-, 1, -, 14, -, 5, 12, -, 3, -, -

Inserting 17
main hash value is 6
There is already an item in 6
double hash value is 16
6 + 1*16 = 22
So, checking at index 22 % 11 = 0
17 is inserted at position 0
17, 1, -, 14, -, 5, 12, -, 3, -, -

HashTable
-----------
0   -      17
1   -      1
2   -     
3   -      14
4   -     
5   -      5
6   -      12
7   -     
8   -      3
9   -     
10      -     

Related Solutions

1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25...
1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25 keys. Do you expect to see any collisions? Why or why not? Yes, because random values likely will land on same locations. No becase there are four times as many slots as needed. 2. Secondary clustering means that elements that hash to the same position will probe to the same alternate cells. Simple hashing uses key%tablesize as the hash function. Which of the following...
Assume that you are hashing key K to a hash table of n slots (indexed from...
Assume that you are hashing key K to a hash table of n slots (indexed from 0 to n - 1). For each of the following functions h(K), answer the following question(s): 1) Is the function acceptable as a hash function (i.e., would the has program work correctly for both insertions and searches), 2) and if so, is it a good hash function? Function rand(n) returns a random integer between 0 and n - 1. Also assume k is a...
Data Structures: Hashing Exercise: 1. a) Given an empty “separate chaining hash table” of size 10,...
Data Structures: Hashing Exercise: 1. a) Given an empty “separate chaining hash table” of size 10, with hash function                        Location = Number modulus 10 Show the hash table after inserting the following numbers: 21, 18, 27 , 31 , 48, 51 , 37, 98, 17 b) What table size would be better? 11? 12? 20? 2. We want to hash name strings into a chaining hash table of size 10, how would you divide the alphabet into 10 groups?...
Develop an algorithm to demonstrate hashing using hash table with modulo as the hash function. Assume...
Develop an algorithm to demonstrate hashing using hash table with modulo as the hash function. Assume the size of the hash table as 10. To avoid collisions in case of identical keys for two different elements, use Linear Probing collision resolution technique. using c++ add comment on the code
Every developer is focused on transmitting data securely. Hashing and hash functions are essential for securing...
Every developer is focused on transmitting data securely. Hashing and hash functions are essential for securing business information and data. While the term cryptographic hash function may sound intimidating, it’s much simpler than it sounds. For this assignment, expand on the information provided in the course and fully address the items below. Write a 2- to 3-page paper in which you: Define cryptographic hash function (CHF). Elaborate on the main properties and definitions of an ideal cryptographic hash function. Propose...
Write a program to insert the following elements into a hash table of size 17. The...
Write a program to insert the following elements into a hash table of size 17. The hash function is X mod 17 where X is the input element.   6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45 Use linear probing to resolve any collisions.
3. Assume a hash table with 7 locations and the hashing function h(i) = i%7. Show...
3. Assume a hash table with 7 locations and the hashing function h(i) = i%7. Show the hash table that results when the integers are inserted in the order given. (10 points each. Total 30) • 5, 11, 18, 23, 28, 13, 25, with collisions resolved using linear probing • 5, 11, 18, 23, 28, 13, 25, with collisions resolved using quadratic probing • 5, 11, 18, 23, 28, 13, 25, with collisions resolved using chaining.
In C++ Use vectors instead of linked lists Create a Hash table program using H(key) =...
In C++ Use vectors instead of linked lists Create a Hash table program using H(key) = key%tablesize with Chaining and Linear probing for a text file that has a list of 50 numbers Ask the user to enter the file name, what the table size is, and which of the two options they want to use between chaining and linear probing
For the division method for creating hash functions, map a key k into one of m...
For the division method for creating hash functions, map a key k into one of m slots by taking the remainder of k divided by m. The hash function is:        h(k) = k mod m,     where m should not be a power of 2. For the Multiplication method for creating hash functions,     The hash function is h(k) = └ m(kA –└ k A ┘) ┘ = └ m(k A mod 1) ┘    where “k A...
SHOW WORK Draw the hash table that results using the hash function: h(k)=kmod7 to hash the...
SHOW WORK Draw the hash table that results using the hash function: h(k)=kmod7 to hash the keys 41, 16, 40, 47, 10, 55. Assuming collisions are handled by Double hashing. SHOW WORK
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT