Question

Select the correct option for the following multiple choice questions or provide short answers accordingly: 1. Consider a has

Explain each answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. b. The hash function returns a fixed number mod N, but the keys of all elements inserted are unique.

Explanation:

a). If hash function returns a unique index then all elements will be stored in unique blocks corresponding to that index value.

  • for example: if N=5  elements have keys 2, 4, 8, 16.(keys value in powers of 2 as given in question).
  • 2 will be stored at block no.2 mod 5=2
  • 4 will be stored at block no. 4 mod 5=4
  • 2 will be stored at block no. 8 mod 5=3
  • 2 will be stored at block no. 16 mod 5=1
  • so if you want to find key element 16 ,just compute 16 mod 5=1 and go to block no 1 and get key element 16.
  • so searching here will be done in O(1) time. it is actually the best case. so this option is wrong.

b). consider N=4 and elements have key values as 2,6,10,14.

  • 2 will be stored at 2 mod 4=2
  • 6 will be stored at 6 mod 4=2
  • 10 will be stored at 10 mod 4=2
  • 14 will be stored at 14 mod 4=2 .so all have to be stored at block no.0. so they would be stored as shown in following image.
  • 1 y 0 hauyh table
  • so if you have to search for key element 14 you have to do 14 mod 4 which is 2 then at block no 2 ,you have to traverse entire linked list. this is worst case scenario. here time complexity is O(n). so this option is correct.

c). hash function can return odd numbers too. for example if N=4 and key element have key value 3 then 3 mod 4=3 which is odd and this means this element will be stored at block no. 3 in hash table. so option is not correct.

d). In worst case find operation will take o(n) time when all key mapped to same block number. so wrong option.

Question 2. d). (log ) would not work for all values. for example if k=264 then ( log | ( 264 )2 | ) = (log | 2128 | ) 128 and hash table size is 65 that is block index would be from 0-64 .so there is no block which have index number 128.so it can't be mapped to any of block. so (d) option is correct.

a) k mod N will work for all element because whenever you divide a number with 65 remainder will be in range of 0-64.

b). In 64 bit integers number of bits which is 1 will be in range of 0-64.

c).in worst case k=264 which will mapped to block no.=(log |(264)) 64. so here index also range between 0-64. so this hash function will also work.

  

Add a comment
Know the answer?
Add Answer to:
Explain each answer. Select the correct option for the following multiple choice questions or provide short...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Questions for Hashing and Skiplists (a) The next two questions relate to the following hashing setup...

    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...

  • 5. Hashing (a) Consider a hash table with separate chaining of size M = 5 and...

    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...

  • It should be really short and simple to do this. #1 [8 points) Sketch a hash...

    It should be really short and simple to do this. #1 [8 points) Sketch a hash table of size N=11, where the hash function is hash(key) = key mod N and chaining is used to resolve collisions, when the following elements are inserted: 20, 42, 45, 49, 62, 72,95 0 1 2 3 4 5 6 7 8 9 10 What is the size of the largest bucket? — #2 [7 points) Sketch a hash table of size N=11, where...

  • Let 'M' denote the hash table size. Consider the following four different hash table implementations: a....

    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...

  • Assume a Hash table has 7 slots and the hash function h(k) = k mod 7...

    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...

  • Consider a hash function hashing a key K to a table of n buckets (indexed from...

    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) =...

  • Need help on problems 3 and 4 only thanks in advance. Define the following terms: hash...

    Need help on problems 3 and 4 only thanks in advance. Define the following terms: hash table hash function perfect hash function What is a collision? Explain three ways of handling collisions (a program is not needed; a clear brief explanation suffices). Consider a hashing scheme that uses linear probing to resolve collisions. Design an algorithm (no code necessary) to delete an item from the hash table. What precautions do you need to take to make it work properly? Given...

  • #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,...

    #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...

  • DATA STRUCTURE: Draw the structure that results from inserting the following numerical keys into each of...

    DATA STRUCTURE: Draw the structure that results from inserting the following numerical keys into each of the structures given, starting from an empty structure. Keys: 17 29 25 48 9 36 3 31 (a) Heap (min heap) (b) Hash table of size 11, using double hashing with primary hash function h(x) =x mod 11 and secondary hash function d(x) = 5 − (x mod 5) (c) AVL Tree

  • Title: Implementation of chained hashing in Java or Python Description: Implement a double linked list with...

    Title: Implementation of chained hashing in Java or Python Description: Implement a double linked list with a procedure for adding list elements. Implement a hash table using chaining and the linked list discussed above. Use Array size m = 7 A hash function of: h = k mod 7 Insert 100 random key values into the table. Key values should be between 0 and 99. Implement a Search procedure that tells whether a particular key value is in the hash...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT