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:

  1. if linear probing is employed,
  2. if quadratic probing is employed, and
  3. if double hashing is employed.

Solutions

Expert Solution

1. Linear Probing

Hash position = (k mod 13 +i) % 13

k = {79, 69, 98, 72, 14, 50, 88, 99, 78, 65} --Set of keys, Taking key one by one from start

1. Hash position = (79 % 13 +0) % 13 = 1, Since 1 is empty

Insert 79 at position 1.

2. Hash position = (69%13+0) % 13 = 4, Since 4 is empty

Insert 69 at position 4.

3. Hash position = (98%13+0) % 13 = 7, Since 7 is empty

Insert 98 at position 7.

4. Hash position = (72%13+0) % 13 = 7, Since 7 is not empty

Hence insert (72%13 +1)% 13=73 % 13=8 at position 8

5. Hash position = (14%13+0) % 13 = 1, Since 1 is not empty

Insert (14%13+1) % 13= 15 % 13=2 at position 2

6. Hash position = (50%13+0) % 13 = 11, Since 11 is empty

Insert 50 at position 11.

7. Hash position = (88%13+0) % 13 = 10, Since 10 is empty

Insert 88 at position 10.

8. Hash position = (99%13+0) % 13 = 8, Since 8 is not empty

(99%13+1)%13=9

Insert 8 at position 9

9. Hash position = (78%13+0) % 13 = 0, Since 0 is empty

Insert 78 at position 0.

10. Hash position = (65%13+0) % 13 = 0

Since 0 is not empty, Try to insert at next one

(65%13+1) % 13=66 % 13=1

But 1 is also not empty, Hence Trying next one

(65%13+2) % 13=67%13=2

But 2 is also not empty, Hence trying at next one

(65%13+3) % 13=68%13=3

Since 3 is empty, Hence

Insert 65 at position 3.

FINAL HASH TABLE:

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

2. Quadratic Probing

Hash position = (h1(k) + c1i + c2i2 ) mod 13

where h1(k)=k mod 13

c1= 3, c2=5

k = {79, 69, 98, 72, 14, 50, 88, 99, 78, 65} --Set of keys, Taking key one by one from start

1. Hash position = (79%13 +0+0) % 13 = 1%13=1 , Since 1 is empty

Insert 79 at position 1.

2. Hash position = (69%13 +0+0) % 13 = 4%13=4 , Since 4 is empty

Insert 69 at position 4.

3. Hash position = (98%13 +0+0) % 13 = 7%13=7 , Since 7 is empty

Insert 98 at position 7.

4. Hash position = (72%13 +0+0) % 13 = 7%13=7 , Since 7 is not empty

( 72%13 + 3*1 + 5*12) % 13=(7+3+5) % 13= 15%13=2

Insert 72 at position 2.

5. Hash position = (14%13 +0+0) % 13 = 14%13=1 , Since 1 is not empty

( 14%13 + 3*1 + 5*12) % 13=(1+3+5) % 13= 9%13=9, 9 is empty

Insert 14 at position 9

6. Hash position = (50%13 +0+0) % 13 = 11%13=11 , Since 11 is not empty

( 50%13 + 3*1 + 5*12) % 13=(11+3+5) % 13= 19%13=6, 6 is empty

Insert 50 at position 6

7. Hash position = (88%13 +0+0) % 13 = 10%13=10 , Since 10 is not empty

Insert 88 at position 10

8. Hash position = (99%13 +0+0) % 13 = 8%13=10 , Since 8 is empty

Insert 99 at position 8

9. Hash position = (78%13 +0+0) % 13 = 0%13=0 , Since 0 is empty

Insert 78 at position 0

10. Hash position = (65%13 +0+0) % 13 = 0%13=0 , Since 0 is not empty

( 65%13 + 3*1 + 5*12) % 13=(0+3+5) % 13= 8%13=8, 8 is not empty

( 65%13 + 3*2 + 5*22) % 13=(0+6+20) % 13= 26%13=0, 0 is not empty

( 65%13 + 3*3 + 5*32) % 13=(0+9+45) % 13= 54%13=2, 2 is not empty

( 65%13 + 3*4 + 5*42) % 13=(0+12+80) % 13= 92%13=1, 1 is not empty

( 65%13 + 3*5 + 5*52) % 13=(0+15+125) % 13= 140%13=10, 10 is not empty

( 65%13 + 3*6 + 5*62) % 13=(0+18+180) % 13= 198%13=3, 3 is empty

Insert 65 at position 3

FINAL HASH TABLE

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

3. Double Hashing

Hash position = (h1(k) + i * h2(k)) mod 13

where h1(k)=k mod 13

h2(k)=1+(k mod 11)

k = {79, 69, 98, 72, 14, 50, 88, 99, 78, 65} --Set of keys, Taking key one by one from start

1. Hash position = (79 % 13 +0 *(1+ 79 % 11)) % 13 = (1+0)%13=1%13=1 , Since 1 is empty

Insert 79 at position 1.

2. Hash position = (69 % 13 +0 *(1+ 69 % 11)) % 13 = (4+0)%13=4%13=4 , Since 4 is empty

Insert 69 at position 4.

3.. Hash position = (98 % 13 + 0 *(1+ 98 % 11) % 13 = (7+0)%13=7%13=7 , Since 7 is empty

Insert 98 at position 7.

4. Hash position = (72 % 13 + 0 *(1+ 72 % 11)) % 13 = (7+0)%13=7%13=7 , Since 7 is not empty

(72 % 13 + 1 *(1+ 72 % 11)) % 13 = (7+7)%13=14%13=1, 1 is also not empty

(72 % 13 + 2 *(1+ 72 % 11)) % 13 = (7+14)%13=21%13=8, Since 8 is empty

Insert 72 at position 8.

5.. Hash position = (14 % 13 +0 *(1+ 14 % 11)) % 13 = (1+0)%13=1%13=1 , Since 1 is not empty

(14 % 13 +1 *(1+ 14 % 11) % 13 = (1+4)%13=5%13=5, 5 is empty

Insert 14 at position 5..

6. Hash position = (50 % 13 + 0 *(1+ 50 % 11)) % 13 = (11+0)%13=11%13=12 , Since 11 is empty

Insert 50 at position 11.

7. Hash position = (88 % 13 + 0 *(1+ 88 % 11)) % 13 = (10+0)%13=10%13=10 , Since 10 is empty

Insert 88 at position 10.

8. Hash position = (99 % 13 + 0 *(1+ 99 % 11)) % 13 = (8+0)%13=8%13=8 , Since 8 is not empty

(99 % 13 + 1 *(1+ 99 % 11)) % 13 = (8+1)%13=9%13=9

Insert 99 at position 9.

9. Hash position = (78 % 13 + 0 *(1+ 78 % 11)) % 13 = (0+0)%13=0%13=0 , Since 0 is empty

Insert 78 at position 0.

10. Hash position = (65 % 13 + 0 *(1+ 65 % 11)) % 13 = (0+0)%13=0%13=0 , Since 0 is not empty

(65 % 13 + 1 *(1+ 65 % 11)) % 13 = (0+11)%13=11%13=10, Since 11 is not empty

(65 % 13 + 2 *(1+ 65 % 11)) % 13 = (0+22)%13=22%13=9, Since 9 is also not empty

(65 % 13 + 3 *(1+ 65 % 11)) % 13 = (0+33)%13=33%13=7, 7 is also not empty

(65 % 13 + 4 *(1+ 65 % 11)) % 13 = (0+44)%13=44%13=5, 5 is also not empty

(65 % 13 + 5 *(1+ 65 % 11)) % 13 = (0+55)%13=55%13=3, 3 is Empty

Insert 78 at position 3.

FINAL HASH TABLE

0 78
1 79
2
3 65
4 69
5 14
6
7 98
8 72
9 99
10 88
11 50
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    h(k, i) = (h1(k) +...
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
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.
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)
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...
Which memory locations are assigned by the hashing function h(k) = k mod 97 to the...
Which memory locations are assigned by the hashing function h(k) = k mod 97 to the records of insurance company customers with these Social Security numbers? (a) 034-56-7981 (b) 220-19-5744 (c) 183-21-1232
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT