Question

3. Assume that you have a seven-slot hash table (the slots are numbered 0 through 6). Show the final hash table that would result if you used the following approach to put 7, 13, 10,6 into the hash (4 points each) the hash function h(k)-k mod 7 and linear probing function the hash function h(k)-k mod 7 and quadratic probing (a) (b)

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

a. Hash function using linear probing will put 7,13,10,6 into hash table as follows:-

h(7) = 7 mod 7 = 0, so 7 will be put into index 0.

h(13) = 13 mod 7 = 6, so 13 will be put into index 6.

h(10) = 10 mod 7 = 3. so 10 will be put into index 3

h(6) = 6 mod 7 = 6. But since index 6 is already occupied by 13, so in linear probing next index for inserting a key is search by moving one index ahead. So after index 6, next index is 0 which is also occupied. So next index 1 is available. So 6 will be inserted at index 7.

Below table shows the entry of these elements into the hash table.

0 1 2 3 4 5 6
7 6 10 13

b. Hash function using quadratic probing will put 7,13,10,6 into hash table as follows:-

h(7) = 7 mod 7 = 0, so 7 will be put into index 0.

h(13) = 13 mod 7 = 6, so 13 will be put into index 6.

h(10) = 10 mod 7 = 3. so 10 will be put into index 3

h(6) = 6 mod 7 = 6. But since index 6 is already occupied by 13, so in quadratic probing, next index to search is i2 index ahead where i is number of collision occurred. For the first time i=1, so 1 index ahead to 6 is index 0, which is also occupied. Now i=2, so the next increment of index will be i2 = 22=4. Since 1+4=5, so index 5 will be searched next. Since index 5 is vacant, so 6 will be put at index 5.

Below table shows the entry of these elements into the hash table.

0 1 2 3 4 5 6
7 10 6 13

Please comment for any clarification.

Add a comment
Know the answer?
Add Answer to:
3. Assume that you have a seven-slot hash table (the slots are numbered 0 through 6)....
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
  • 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...

  • Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function h(x) = x...

    Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function h(x) = x (mod () 10), show the resulting: a. Separate chaining hash table b. Hash table using linear probing c. Hash table using quadratic probing d. Hash table with second hash function h2(x) = 7 - (x mod 7) *Assume the table size is 10.

  • 11. (10 Points) Draw the final result after inserting keys 24, 25, 50, 38, 12, 90...

    11. (10 Points) Draw the final result after inserting keys 24, 25, 50, 38, 12, 90 into a hash table with collisions resolved by (a) linear probing, (b) chaining. Let the table have 13 slots with addresses starting at 0, and let the hash function be h(k) k mod 13 (a) (5 Points) Linear Probing 0 1 2 3 4 5 6 789 10 11 12 [ANSWER] (b) (5 Points) Separate Chaining ANSWER]

  • Exercise 3 (5 points). Suppose we have a hash table of m = 9 slots, and...

    Exercise 3 (5 points). Suppose we have a hash table of m = 9 slots, and we resolve collisions by chaining. Demonstrate what happens when we insert the keys 5, 28, 19, 15, 20, 33, 12, 17, 10. Use the division-method hash function h (k) = k mod 9.

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

  • 6. A hash table has size 7, uses quadratic probing (f(i) = 1), and has hash...

    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 data is to be stored in a hash table using the following keys: 62,77.26, 42,...

    Assume data is to be stored in a hash table using the following keys: 62,77.26, 42, 52,76 Assume the hash table size is 7, the hash function used is the modulo function i.e. h/key) = key % table_size, and collisions are handled using linear probing. What's the content of the table after all keys are mapped to the hash table? (List keys starting from table index 0 and on Separate numbers by a comma and a single space, and indicate...

  • (in Java) We wish to insert the following strings into a hash table: BEN AL SUE...

    (in Java) We wish to insert the following strings into a hash table: BEN AL SUE CHUCK KAREN MIKE SAM MIKE ALICE TARA TIM BOB Let's make the hash table size p=19 ( 19 is a prime ). Use letter encodings where A maps to 1, B maps to 2, etc and strings map to powers of 26. For example, "ABC" would map to 1*(26^2) + 2*(26^1)+ 3*(26^0) mod 19 (you might find the web site Wolfram Alpha helpful. Just...

  • Hash the values 94, 11, 39, 20, 16, 5, 12, 44, 13, 88 and 23 into...

    Hash the values 94, 11, 39, 20, 16, 5, 12, 44, 13, 88 and 23 into a hash table with 11 slots. Handle collisions by linear probing. Use the hash function: h(i) (3 * i + 5) % 11 Type in each key on the same line as the index of the slot where it is eventually inserted. YOUR ANSWER TO QUESTION A: 0: 1: 2: 3: 5: 7: 9: 10:

  • 1.) The value 80 will place into which slot 0-9 in a hash table using the...

    1.) The value 80 will place into which slot 0-9 in a hash table using the hash function h(k) = k mod 10 Your Answer: 2.)Given the following 2 functions - what is the value of calling fb(5,2)? function fa(x, y){ if (y == 0) return 0; return (x + fa(x, y-1)); } function fb(x, y) { if (y == 0) return 1; return fa(x, fb(x, y-1)); }

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