Question

In: Computer Science

Assume that we define h1(k) = k mod 13 and h2(k) = 1 + (k mod...

Assume that we define h1(k) = k mod 13 and h2(k) = 1 + (k mod 11).
For the opening addressing, consider the following methods
Linear Probing
Given an ordinary hash function h’: U {0, 1, 2, …, m-1}, the method of linear probing
uses the hash function
   h(k, i) = (h1(k) + i) mod m for i = 0, 1, 2, …, m-1.
Quadratic Probing
Uses a hashing function of the form
   h(k, i) = (h1(k) + c1i + c2i2 ) mod m,   
where h1 is an auxiliary hash function, c1 and c2 0 are auxiliary constants c1 3 c2 = 5,
and i = 0, 1, 2, …, m-1.
Double hashing
Uses a hashing function of the form
    h(k, i) = (h1(k) + i h2(k) ) mod m,   
where h1 and h2 are auxiliary hash functions.
The value of h2(k) must never be zero and should be relatively prime to m for the sequence
to include all possible address.

Given K = {79, 69, 98, 72, 14, 50, 88, 99, 78, 65} and the size of a table is 13, with indices counting from 0, 1, 2, …, 12. Store the given K in a table with the size 13 counting the indices from 0, 1, 2, …, 12. Show the resultant table with 10 given keys for each method applied:
⦁   if linear probing is employed,
⦁   if quadratic probing is employed, and
⦁   if double hashing is employed.

Solutions

Expert Solution

K={79, 69, 98, 72, 14, 50, 88, 99, 78, 65}

BY linear probing we will save the key at the indices which comes as remainder

if collision occurs then will use h(k, i) = (h1(k) + i) mod m  this formula to find next empty space

m=12

h1= 79 mod 12 = 7

h2 = 69 mod 12 = 9

h3 = 98 mod 12 = 2

h4= 72 mod 12 = 0

h5 = 14 mod 12 = 2 collision occurs so , will add 1 to hash key then as using linear probing

  h5 = (14+1) mod 12 = 3

h6 = 50 mod 12 = 2 collision occurs so , will add 1 to hash key then

h6 = 50 +1 mod 12 = 3 collision

h6 = 51+1  mod 12 = 4

h7= 88 mod 12 = 4 collision occurs, As 4 is already occupied by hash key 50

h7= 88 +1 mod 12 = 5

h8= 99 mod 12 = 3  collision occurs, As 3 is already occupied by hash key 14

h8= 99+1 mod 12 = 4

h8= 100+1 mod 12 = 5

h8= 101 + 1 mod 12 = 6

h9 = 78 mod 12 = 6 collision occurs, As indicie 6 is already occupied by hash key 99

  h9 = 78 +1 mod 12 = 7

h9 = 79 + 1 mod 12 = 8

h10= 65 mod 12 = 5  collision occurs, As 5 is already occupied by hash key 88

h10= 65 +1 mod 12 = 6

h10= 66 +1 mod 12 = 7

h10= 67 +1 mod 12 = 8

h10= 68 +1 mod 12 = 9

h10= 69 +1 mod 12 = 10

HASH VALUE HASH KEY
0 72
1
2 98
3 14
4 50
5 88
6 99
7 79
8 78
9 69
10 65
11
12

BY Quadratic probing we will save the key at the indices which comes as remainder

if collision occurs then will use h(k, i) = (h1(k) + c1i + c2i2 ) mod m this formula to find next empty space

m=12 ,c1 =3 c2 = 5

h1= 79 mod 12 = 7

h2 = 69 mod 12 = 9

h3 = 98 mod 12 = 2

h4= 72 mod 12 = 0

h5 = 14 mod 12 = 2 collision occurs so , will add 1 to hash key then

  h5 = ( 14 + (3*1)+ (5* 12)) mod 12 = 22 MOD 12 = 10

h6 = 50 mod 12 = 2 collision occurs so , will add 1 to hash key then

h6 = ( 50 + (3*1)+ (5* 12)) mod 12 = 58 MOD 12 = 10 collsion occurs

h6 = ( 50 + (3*2)+ (5* 22)) mod 12 = 76 mod 12 = 4

h7= 88 mod 12 = 4 collision occurs, As 4 is already occupied by hash key 50

h7= ( 88 + (3*1)+ (5* 12)) mod 12 = 96 mod 12 =0 collsion occurs again

   h7= ( 88 + (3*2)+ (5* 22)) mod 12 = 114 mod 12 = 6

h8= 99 mod 12 = 3  

h9 = 78 mod 12 = 6 collision occurs, As indicie 6 is already occupied by hash key 88

h9 = ( 78+ (3*1)+ (5* 12)) mod 12 = 86 mod 12 =2 collision occurs as 98 is already at indices 2.

h9 = ( 78 + (3*2)+ (5* 22)) mod 12 = 114 mod 12 = 6 collision occurs as 88 is already at indices 6.

   h9 = ( 78 + (3*3)+ (5* 32)) mod 12 = 132 mod 12 = 0 collision occurs as 72 is already at indices 0.

h9 = ( 78 + (3*4)+ (5* 42)) mod 12 = 170 mod 12 = 2 collision occurs as 98 is already at indices 2.

h9 = ( 78 + (3*5)+ (5* 52)) mod 12 = 218 mod 12 = 2 collision occurs as 98 is already at indices 2.

h9 = ( 78 + (3*6)+ (5* 62)) mod 12 = 276 mod 12 = 0 collision occurs as 72 is already at indices 0.

h9 = ( 78 + (3*7)+ (5* 72)) mod 12 = 344 mod 12 = 8

h10 = 65  mod 12 = 5  

HASH VALUE(Indices) HASH KEY
0 72
1
2 98
3 99
4 50
5 65
6 88
7 79
8 78
9 69
10 14
11
12

BY Double Hashing we will save the key at the indices which comes as remainder

if collision occurs then will use    h(k, i) = (h1(k) + i h2(k) ) mod m,   this formula to find next empty space

h2(k) this the second hash which we will find if collision occurs with the use of prime no. and then will put the value of i linearly.

m=12

h1= 79 mod 12 = 7

h2 = 69 mod 12 = 9

h3 = 98 mod 12 = 2

h4= 72 mod 12 = 0

h5 = 14 mod 12 = 2 collision occurs so , As 98 is already at that place.

  h(k, i) = (h5 + i hash2(k) ) mod m,

hash2(5) = 7 - (14 mod 7) = 7

h5 = (2 + 1* 7) mod 12 = 9 mod 12 =2 collsion as 98 is already there at that place.

h5 = (2 + 2* 7) mod 12 = 16 mod 12 =4

h6 = 50 mod 12 = 2 collision occurs so , As 98 is already at that place

h(k, i) = (h6 ​​​​​​​ + i hash2(k) ) mod m,

hash2(6) = 7 - (50 mod 7) = 6

h6 = (2 + 1* 6) mod 12 = 8

h7= 88 mod 12 = 4 collision occurs, As 4 is already occupied by hash key 50

h(k, i) = (h6 ​​​​​​​ + i hash2(k) ) mod m,

hash2(7) = 7 - (88 mod 7) = 3

h7 = (2 + 1* 3) mod 12 = 5

h8= 99 mod 12 = 3  

h9 = 78 mod 12 = 6

h10= 65 mod 12 = 5  collision occurs, As 5 is already occupied by hash key 88

h(k, i) = (h10 ​​​​​​​ + i hash2(k) ) mod m,

hash2(10) = 7 - (65 mod 7) = 5

h10 = (2 + 1* 5) mod 12 = 7 collision occurs, As 7is already occupied by hash key 79

h10 = (2 + 2* 5) mod 12 = 0 collision occurs, As 0 is already occupied by hash key 72

h10 = (2 + 3* 5) mod 12 = 5 collision occurs, As 5 is already occupied by hash key 88

h10 = (2 + 4* 5) mod 12 = 10 it is there.

HASH VALUE HASH KEY
0 72
1
2 98
3 99
4 14
5 88
6 78
7 79
8 50
9 69
10 65
11
12

Related Solutions

Assume that we define h1(k) = k mod 13 and h2(k) = 1 + (k mod...
Assume that we define h1(k) = k mod 13 and h2(k) = 1 + (k mod 11). For the opening addressing, consider the following methods Linear Probing        Given an ordinary hash function h’: U → {0, 1, 2, …, m-1}, the method of linear probing        uses the hash function             h(k, i) = (h1(k) + i) mod m     for i = 0, 1, 2, …, m-1. Quadratic Probing       Uses a hashing function of the form            ...
<html> <head>     <title>Nick D'Angelo</title> </head> <body>     <h1>This is a header</h1>     <h2>This is a subheader</h2>  &nbs
<html> <head>     <title>Nick D'Angelo</title> </head> <body>     <h1>This is a header</h1>     <h2>This is a subheader</h2>     <p>The quick <b>brown</b> fox jumped <i>over</i> the lazy dog.</p>     <!--additional paragraph-->     <!--here two words are bold and two are italicized-->     <p>Pack my <b>box</b> with <i>five</i> dozen <b>liquor</b> <i>jugs</i>. Go to <a href='https://www.esu.edu' target="_blank">site</a></p>     <a href="http://ndangelo.com">Nick's Homepage</a>     <a href="http://ndangelo.com" target="_blank">Nick's Homepage</a> </body> <html> Add an Ordered, Unordered, Definition and Nested list to your html file (one for each). Each should be at least 10 lines or more....
a) Use Fermat’s little theorem to compute 52003 mod 7, 52003 mod 11, and 52003 mod 13.
  a) Use Fermat’s little theorem to compute 52003 mod 7,52003 mod 11, and 52003 mod 13. b) Use your results from part (a) and the Chinese remaindertheorem to find 52003 mod 1001. (Note that1001 = 7 ⋅ 11 ⋅ 13.)
∆H1,  ∆H2, and ∆H3 are the enthalpy of the following reactions: NaOH(s) àNa+(aq) + OH-(aq)            ∆H1...
∆H1,  ∆H2, and ∆H3 are the enthalpy of the following reactions: NaOH(s) àNa+(aq) + OH-(aq)            ∆H1 NaOH(s) + H+(aq) + Cl-(aq)àH2O(l) + Na+(aq) + Cl-(aq)    ∆H2 Na+(aq) + OH-(aq) + H+(aq) + Cl-(aq)à H2O(l) + Na+(aq) + Cl-(aq)           ∆H3 Please write an equation that will demonstrate the relationship among ∆H1,  ∆H2, and ∆H3 based on Hess's Law.
We are to test H0 : µ = 1200 versus H1 : µ ≠ 1200 Assume...
We are to test H0 : µ = 1200 versus H1 : µ ≠ 1200 Assume that the random variable of interest Y~N( µ, σ2), where both mean µ and standard deviation were unknown. And the sample mean Ῡ=1422.2, sample standard deviation s=246.86, obtained from a random sample of size n=10 taken from this population. Compute the following: a) P- value of the test b) Probability of making Type II error of this test at µ= 1300
Compute the following: (a) 13^2018 (mod 12) (b) 8^11111 (mod 9) (c) 7^256 (mod 11) (d)...
Compute the following: (a) 13^2018 (mod 12) (b) 8^11111 (mod 9) (c) 7^256 (mod 11) (d) 3^160 (mod 23)
1) Describe the main adverse effects of H1 an H2 receptor antagonists. 2) Describe the main...
1) Describe the main adverse effects of H1 an H2 receptor antagonists. 2) Describe the main contraindications of H1 an H2 receptor antagonists. 3) Describe the main therapeutic uses of H1 and H2 receptor antagonists.
For m, n in Z, define m ~ n if m (mod 7) = n (mod...
For m, n in Z, define m ~ n if m (mod 7) = n (mod 7). a. Show that -341 ~ 3194; that is to say 341 is related to 3194 under (mod 7) operation. b. How many equivalence classes of Z are there under the relation ~? c. Pick any class of part (b) and list its first 4 elements. d. What is the pairwise intersection of the classes of part (b)? e. What is the union of...
This question related to thermodynamics. With a throtteling valve in a refrigiration system h1 = h2.  ...
This question related to thermodynamics. With a throtteling valve in a refrigiration system h1 = h2.   If h1 = h2 and only pressure is changed by a throttling valve then why can't an ideal gas be used? Why do refrigerants need to be used?
Suppose we seal I2(g) and H2(g) in a vessel at T = 400 K with partial...
Suppose we seal I2(g) and H2(g) in a vessel at T = 400 K with partial pressures PI2 = 0.067 atm and PH2= 1.275 atm. At this temperature H2 and I2 do not react readily to form HI(g), although in principle if we waited long enough they would produce HI(g) at its equilibrium partial pressure. Instead of waiting for this to happen, we choose to heat the gases in the sealed flask to 600 K, where they readily react to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT