Q a)
h(x) = x mod 5
1)
Numbers-> 11 34 76 55 24 98 66 45 13
2)
Calculate hash of each element and chain elements
Bucket Elements
0: 55->45
1: 11->76->66
2: 13->
3: 98->
4: 34->24
3)
Average Probes = Total probes/Total number of elements
inserted
= (1+1+2+1/8) = 0.5
1 for 45, 76, 24 and 2 for 66
--------------------------------------------------------------------------------------------------------------------------------
Q b)
h(x) = x mod 10
1)
key=23, hash=3, index=3
key=45, hash=5, index=5
key=55, hash=5, index=6 (after 1 probe)
key=73, hash=3, index=4 (after 1 probe)
key=83, hash=3, index=7 (after 3 probes)
Key | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
element | 23 | 73 | 45 | 55 | 83 |
2)
delete 73
Key | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
element | 23 | 45 | 55 | 83 |
Insert 93, hash=3 index=4 after 1 probe
Key | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
element | 23 | 93 | 45 | 55 | 83 |
---------------------------------------------------------------------------------------------------------------------------------------
Q c)
h1(x) = x mod 10
h2(x) = 5-(x mod 5)
1)
->key=23
h1(x)=3
h2(x)=5-(3)=2
index=3 (no probing)
->key=45
h1(x)=5
h2(x)=5-(0)=5
index=5 (no probing)
->key=62
h1(x)=2
h2(x)=5-(2)=3
index=2 (no probing)
->key=43
h1(x)=3
h2(x)=5-(3)=2
index=3 (full), 5(full), 7(empty)
index = 7 ( after 2 probes)
->key=12
h1(x)=2
h2(x)=5-(2)=3
index=2 (full), 5(full), 8(empty)
index = 8 ( after 2 probes)
2)
Example 45,55
h1(45) = 5, h2(45)=5
h1(55) = 5, h2(55)=5
once 45 is inserted, 55 will probe at 5,0,5,0.. indices
5. Hashing (a) Consider a hash table with separate chaining of size M = 5 and...
Let 'M' denote the hash table size. Consider the following four different hash table implementations: a. Implementation (I) uses chaining, and the hash function is hash(x)x mod M. Assume that this implementation maintains a sorted list of the elements (from biggest to smallest) for each chain. b. Implementation (II) uses open addressing by Linear probing, and the hash function is ht(x) - (hash(x) + f(i)) mod M, where hash(x)x mod M, and f(i)- c. Implementation (III) uses open addressing by...
Insert the following keys into the following hash table, size 10: a. our hash function is simply key mod 10 b. Assume open hashing Keys: 566 909 212 655 123 444 974 321
10. Submission In this question you will work with a hash table that uses double hashing. The hash table is size 11, the primary hash function is h(K)-K mod 11, and the secondary hash function is hp(K)-(K mod9) +1 Take an empty hash table. Take your student number and split it into 4 2-digit integers. Insert each of these 2-digit numbers in the order in which they appear in your student number into the empty heap. Then insert the values...
6. A hash table has size 7, uses quadratic probing (f(i) = 1), and has hash function h(2) = 2%7. (Recall, % is the Java "mod" function.) Draw the contents of the hash table after the following sequence of insertions: insert 0, insert 7, insert 14, insert 21. The hash table is initially empty.
Assume a Hash table has 7 slots and the hash function h(k) = k mod 7 is used. The keys 14, 3, 11, 6, 10, 4, 20, and 17 are inserted in the table with collision resolution by chaining. Assume that the keys arrive in the order shown. (a) Show the hash table obtained after inserting all 8 keys. [Show only the final table] (b) Under the assumption that each key is searched with probability 1/8, calculate expected number of...
Insert elements into a hash table implemented using chain hashing, as an array of linked list in which each entry slot is as a linked list of key/value pairings that have the same hash (outcome value computed using certain hash function). You are allowed to use “Hash Function”, h(k) = k % x where, x is the value you will need to decide to use, that you find appropriate for this implementation. The main requirements are the following: 1. Input:...
#3 [3 points] Sketch a hash table of size N=11, where the hash function is hash(key) = key mod N and quadratic probing is used to resolve collisions, after the following elements are inserted: 20, 42, 45, 49, 62, 72, 95. The probes are based on this equation: (H+c1∗i+c2∗i2)mod(N) and c1=1, c2=1. If direct hashing was used to store the same elements as the previous problems (20, 42, 45, 49, 62, 72, 95), what should be the minimum size of...
Consider a hash function hashing a key K to a table of n buckets (indexed from 0 to n - 1). Which of these would be acceptable hash functions -- meaning that they would work correctly for both insertions and searches? Assume the function Random(n) returns an integer between 0 and n - 1, inclusive. (Select all that apply). Group of answer choices 1. h(K) = k mod n 2. h(K) = Random(n) 3. h(K) = n 4. h(K) =...
C programming Problem 3 [Set via Hashing] As mentioned in the lecture, a hash table can be used to implement a Set ADT. Let's try to use the template below to implement a Set with double hashing. Here we assume the Set contains names with 3 characters long. Since it is a Set, we do not need to have an explicit value for each key. We will use a token value of 1 if a name belongs to the Set....
Given the input sequence 4371, 1323, 6173, 4199, 4344, 9679, 1989, a hash table of size b=10, and a hash function h(x)=x mod b, show each step needed to build a hash table A closed hash table using double hashing, with the second hash function as h′(x)=7 − (x mod 7) This yields the sequence of hash functions hi(x)=(x mod b + i⋅ (7 − ( x mod 7)))mod b for i=0,1,…