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) = (k + Random(n)) mod n
Answer: --------- 1. h(K) = k mod n 3. h(K) = n Explanation: -------------- 1. h(K) = k mod n This is a very good hash function used everywhere 2. h(K) = Random(n) hash of a key can/should not be random. 3. h(K) = n This is a bad hash function. but still we can use this as a hash function for insert/search using chaining method for collision resolution. 4. h(K) = (k + Random(n)) mod n hash of a key can/should not be random.
Consider a hash function hashing a key K to a table of n buckets (indexed from...
5. Hashing (a) Consider a hash table with separate chaining of size M = 5 and the hash function h(x) = x mod 5. i. (1) Pick 8 random numbers in the range of 10 to 99 and write the numbers in the picked sequence. Marks will only be given for proper random numbers (e.g., 11, 12, 13, 14 ... or 10, 20, 30, 40, .. are not acceptable random sequences). ii. (2) Draw a sketch of the hash table...
1. Suppose that a hash table contains hash_size = 13 entries indexed from 0 through 12 and that the following keys are to be mapped into the table: 24 34 33 55 46 38 37 The hash function determines the hash address by first summing all digits of a key (in ordinary decimal representation) and then applying % hash_size. Answer the following questions. Assume that double hashing g(k) = 7 – (k mod 7) is used. Present the hash table...
Double hashing is scheme for resolving collisions that uses two hash functions HCk, m) and hCk,m). It is similar to linear hashing except that instead of changing the index by 1, the value of the second hash function is used From the view of the general scheme, the Io(k, mHCk, m) Hi(k, m) -(H(k, m)+ h(k,m)) mod m H2 (k, m) = (H(k, m)+ 2 h(k,m)) mod m hash functions are. Hi (k, m) (H(k , m)+ h(k , m))...
#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...
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...
2. (10 points.) The procedure HASH-SEARCH takes a hash table T[O : m-1) and a key k as its parameters. Each element of T is either a key or NIL. The procedure searches for k in T by probing. If it finds k, then it returns the index j where k appears in T. If it cannot find k, then it returns -1. (A procedure very much like HASH-SEARCH is discussed on pages 269–274 of Cormen.) HASH-SEARCH(T, k) i= 0...
Part 5. Suppose that your hash function resolves collisions using the open addressing method with double hashing. The double hashing method uses two hash functions h and h'. Assume that the table size N = 13, h(k) = k mod 13, h'(k) = 1 + (k mod 11), and the current content of the hash table is: 0 1 2 3 6 7 8 9 10 11 12 4 17 5 98 If you insert k = 14 to this...
Questions for Hashing and Skiplists (a) The next two questions relate to the following hashing setup table size is 11 elements . hash keys are lower-case alphabetic strings . the hash function is h(k) code(last Letter (k)) mod 1 1 Where last Letter extracts the last letter from its input and code returns an integer representing the position of the letter in the alphabet (starting at zero). So, for example h(anna) returns 0, h(mob) returns 1 and h(noon) returns 2...
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:...
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...