0% found this document useful (0 votes)
30 views

Chapter 5

The document discusses using different hash table implementations to store a set of sample data. It provides examples of separate chaining hash tables, open addressing with linear probing, open addressing with quadratic probing, and open addressing with a secondary hash function. It also discusses rehashing tables into a larger size and shows an example of inserting keys into an extendible hashing data structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Chapter 5

The document discusses using different hash table implementations to store a set of sample data. It provides examples of separate chaining hash tables, open addressing with linear probing, open addressing with quadratic probing, and open addressing with a secondary hash function. It also discusses rehashing tables into a larger size and shows an example of inserting keys into an extendible hashing data structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

I Problem DS-05-01(a) Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a

hash function h(X) = X (mod 10), show the result of using separate chaining hash table.
Solution. On the assumption that we add collisions to the end of the list, the separate
chaining hash table that results is shown below.

1
I Problem DS-05-01(b) Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a
hash function h(X) = X (mod 10), show the result of using open addressing hash table
with linear probing.
Solution.

1
I Problem DS-05-01(c) Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a
hash function h(X) = X (mod 10), show the result of using open addressing hash table
with quadratic probing.
Solution.

1
I Problem DS-05-01(d) Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a
hash function h(X) = X (mod 10), show the result of using open addressing hash table
with second hash function h2 (X) = 7 − (X mod 7).
Solution. Item 1989 cannot be inserted into the table because hash2 (1989) = 6, and
the alternative locations 5, 1, 7 and 3 are already taken. The table at this point is as
follows:

1
I Problem DS-05-02(a) Show the result of rehashing the hash table in Exercise 5.1(a).

Solution. When rehashing, we choose a table size that is roughly twice as large and
prime. In our case, the appropriate new table size is 23, with hash function h(X) = X
(mod 23).

0
1 - - 4371 -
2
3
4
5
6
7
8
9 - - 6173 -
10
11 - - 1989 -
12 - - 1323 -
13 - - 4199 -
14
15
16
17
18
19 - - 9679 -
20 - - 4344 -
21
22

1
I Problem DS-05-02(b,c,d) Show the result of rehashing the hash table in Exercise
5.1(b,c,d).
Solution. When rehashing, we choose a table size that is roughly twice as large and
prime. In our case, the appropriate new table size is 23, with hash function h(X) = X
(mod 23). Since there are no collision in the process of rehashing, the hash tables of three
cases (b), (c) and (d) are the same, which is shown below.

0
1 4371
2
3
4
5
6
7
8
9 6173
10
11 1989
12 1323
13 4199
14
15
16
17
18
19 9679
20 4344
21
22

1
I Problem DS-05-14 Show the result of inserting the keys 10111101, 00000010,
10011011, 10111110, 01111111, 01010001, 10010110, 00001011, 11001111, 10011110, 11011011,
00101011, 01100001, 11110000, 01101111 into an initially empty extendible hashing data
structure with M = 4.
Solution.

You might also like