Question

Need help with algorithm homework, please answer with complete steps. Will give thumbs up to correct...

Need help with algorithm homework, please answer with complete steps. Will give thumbs up to correct and complete answer, thanks!

Given a hash function h(x) = x mod 10 with inputs: 4491, 1443, 6293, 4319, 4464, 9799, 2109. Do the following:

(a) Hash table with quadratic probing

(b) Given new hash function h(x) = x mod 19, rehash part a, with order following the old hash table order, not original order at the beginning

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

Part A)

Hash Function is used to map the values in the hash table .

H(x) = x mod 10

where x is the value that needed to be mapped

Apply Hash Function to each value to get the slot

1 x = 4491

H(4491) = 4491 mod 10 = 1

So 4491 is stored at slot 1

2. x = 1443

H(1443) = 1443 mod 10 = 3

So 1443 is stored at slot 3

3.

x= 6293

H(6293) = 6293 mod 10 = 3

Now at slot 3 we already have 1443 so collision is there

Now Use quadratic probing to resolve resolution

Now Hash Function is H(x) = ( H(x) + i^2 ) mod 10 for all i >=1

First i = 1

H( 6293 ) = ( 3 + 1 x 1 ) mod 10 = 4

So now 6293 is stored at slot 4

4.

x=4319

H(4319 ) = 4319 mod 10 = 9

Now 4319 is stored at Slot 9

5.

x= 4464

H(4464) = 4464 mod 10 = 4

Now already at slot 4 6293 is stored so Collision Occurs

H(4464) = ( 4 + 1 x 1 ) mod 10 = 5

Hence 4464 is stored at slot 5

6.

x=9799

H( 9799) = 9799 mod 10 = 9

Now already 4319 is stored at slot 9 so collision occurs

Now

H(9799) = ( 9 + 1 x 1 )mod 10 = 0

Now 9799 is stored at Slot 0

7.

x=2109

H(2109 ) = 2109 mod 10 = 9

So collision occurs

For i =1

H( 2109 ) = ( 9 + 1x1 ) mod 10 = 0

Again Collision occurs at slot 0

For i =2

H( 2109 ) = ( 9 + 2 x 2 ) mod 10 = 3

Again Collision is there

For i = 3

H(2109 ) = ( 9 + 3 x 3 ) mod 10 = 18 mod 10 = 8

Now finally 2109 is stored at Slot 8

So now finally Hash Table is  

Index Value Key Stored
0 9799
1 4491
2
3 1443
4 6293
5 4464
6
7
8 2109
9 4319


Part B )

Now sequence of Insertion Key in hash table is

9799, 4491 , 1443 , 6293 , 4464 , 2109 , 4319

Now Hash These values using Hash Function

H(x) = x mod 19

So mapping is

1.

x= 9799

H( 9799) = 9799 mod 19 = 14

So 9799 is stored at Slot 14

2.

x= 4491

H(4491) = 4491 mod 19 = 7

So 4491 is stored At Slot 7

3.

x= 1443

H(1443) = 1443 mod 19 = 18

So 1443 is stored at Slot 18

4.

x= 6293

H(6293) = 6293 mod 19 = 4

So 6293 is stored at Slot 4

5.

x= 4464

H(4464) = 4464 mod 19 = 18

So now collision occur

H(4464 ) = ( 18 + 1 x 1 )mod 19 = 0

So 4464 is stored at Slot 0

6.

x= 2109

H(2109 ) = 2109 mod 19 = 0

So collision occurs

H( 2109 ) = ( 0 + 1 x 1 ) mod 19 = 1

So 2109 is stored at Slot 1

7.

x = 4319

H(4319) = 4319 mod 19 = 6

So 4319 is stored at slot 6

So Finally Hash Table we get as

Index Value Key Stored
0 4464
1 2109
2
3
4 6293
5
6 4319
7 4491
8
9
10
11
12
13
14 9799
15
16
17
18 1443

This is how you can do hashing on values and Make the Hash Table and here to resolve the collision we have used Quadratic Probing

If u like the answer do give it a thumbs up and have any doubt comment it

Add a comment
Know the answer?
Add Answer to:
Need help with algorithm homework, please answer with complete steps. Will give thumbs up to correct...
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
  • 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...

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

  • I need help for Q11 Please if you can, answer this question too. I need B...

    I need help for Q11 Please if you can, answer this question too. I need B Q11. A complete graph is a graph where all vertices are connected to all other vertices. A Hamiltonian path is a simple path that contains all vertices in the graph. Show that any complete graph with 3 or more vertices has a Hamiltonian path. How many Hamiltonian paths does a complete graph with n vertices has? Justify your answer Q1. Draw thee 13-entry hash...

  • Please answer all parts to 4 signifigant figures for a thumbs up, thanks! [2pta The two...

    Please answer all parts to 4 signifigant figures for a thumbs up, thanks! [2pta The two graphs below show approximate phase Bode diagrams for transfer functions H(s). Each original function can be written in the form: For each given graph, determine the corresponding parameters of H s). Enter T" if a parameter is impossible to determine phase of H a. 180° phase of H 900 90° log ? log co -900 -900 -180° 3-2-1 0 1 2 3 3 -2-1...

  • please answer both parts to the question! will give thumbs up. thanks! c. Consider the following...

    please answer both parts to the question! will give thumbs up. thanks! c. Consider the following chemical reaction: 2A + 3B In the course of studying this reaction, we measure the concentration of A as the reaction proceeds and create three graphs: . . graph 1: The concentration of A is plotted as a function of time. graph 2: The logarithm of the concentration of A is plotted as a function of time. graph 3: The reciprocal of the concentration...

  • Please help me answer all questions. I will give a thumbs up if all questions are...

    Please help me answer all questions. I will give a thumbs up if all questions are answered. This is a multiple-choice test consisting of 35 questions. Each correct answer is worth three points for a total of 105 points. Mark all answers on your 882-scantron form. the scantron will be graded 1. Given the initial rate data for the reaction A + B C, determine the rate equation for the reaction. 0.020 0.020 0.060 0.030 0.060 0.030 0.010 0.040 0.090...

  • Please help, will give thumbs up for correct answer! Thanks Scribners Corporation produces fine papers in...

    Please help, will give thumbs up for correct answer! Thanks Scribners Corporation produces fine papers in three production departments-Pulping, Drying, and Finishing. In the Pulping Department, raw materials such as wood fiber and rag cotton are mechanically and chemically treated to separate their fibers. The result is a thick slurry of fibers. In the Drying Department, the wet fibers transferred from the Pulping Department are laid down orn porous webs, pressed to remove excess liquid, and dried in ovens. In...

  • please answer this i need it asap ill make sure to rate and give thumbs up! 1. A company has five machines (1 lathe, 2 mills and 2 drills) arranged sequentially to produce a batch of 200 parts. Th...

    please answer this i need it asap ill make sure to rate and give thumbs up! 1. A company has five machines (1 lathe, 2 mills and 2 drills) arranged sequentially to produce a batch of 200 parts. The following table lists the setup and work cycle times per piece for the five machines. Delay (hr) 10 10 10 10 10 Work cycle time (min) 15 27 12 Setup time (hr.) 2.50 1.25 1.50 0.50 0.75 Machine 1. Lathe 2....

  • **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the...

    **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the creatures from the classic science-fiction film "The Day of the Triffids") is an algorithm that enciphers a plaintext message by encoding each letter as a three-digit number and then breaking up and rearranging the digits from each letter's encoded form. For this assignment, you will create a set of Python functions that can encode messages using this cipher (these functions...

  • Please provide original Answer, I can not turn in the same as my classmate. thanks In...

    Please provide original Answer, I can not turn in the same as my classmate. thanks In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a “next” pointer. Textbook Type Attribute String title String author String ISBN Textbook* next Textbook Type Attribute String title String...

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