You are on page 1of 4

PROGRESSTEST 2 - CSI

Name : Trinh Tan Quang Bao – DE170271


Class : AI17D01
P13-1. Given the old master file and the transaction file in Figure 13.16, find the new
master file. If there are any errors, create an error file too.
Figure 13.16 Problem P13-1
Old master file

Key Name Pay rate


14 John Vu 17.00
16 George Brown 18.00
17 Duc Lee 11.00
20 Li Nguyen 12.00
26 Ted White 23.00
31 Joanne King 27.00
45 Brue Wu 12.00
89 Mark Black 19.00
92 Betsy Yellow 14.00

Transaction file

Action Key Name Pay rate


A 17 Martha Kent 17.00
D 20
C 31 28.00
D 45
A 90 Orva Gilbert 20.00
My solution: New master file

Key Name Pay rate


14 John Vu 17.00
16 George Brown 18.00
17 Martha Kent 17.00

26 Ted White 23.00


31 Joanne King 28.00

89 Mark Black 19.00


90 Orva Gilbert 20.00
92 Besty Yellow 14.00
P13-2. Create an index file for Table 13.1.
Table 13.1 Problem P13-2
Key Name Department
123453 John Adam CIS
114237 Ted White MTH
156734 Jimmy Lions ENG
093245 Sophie Grands BUS
077654 Eve Primary CIS
256743 Eva Lindens ENG
423458 Bob Bauer ECO

My solution:

Key Name Department


077654 Eve Lindens CIS
093245 Sophie Grands BUS
114237 Ted White MTH
123453 John Adam CIS
156734 Jimmy Lions ENG
256743 Eva Lindens ENG
423458 Bob Bauer ECO

P13-3.A hash file uses a modulo division method with 41 as the divisor. What is the address for each
of the following keys? a. 14232 b. 12560 c. 13450 d. 15341

My solution:
To find the address for each key using modulo division method, we need to divide the key by the
divisor (41) and take the remainder. The remainder will be the address for the key.
a. 14232 % 41 = 5 The address for key 14232 is 5 + 1 = 6.
b. 12560 % 41 = 14 The address for key 12560 is 14 + 1 = 15.
c. 13450 % 41 = 2 The address for key 13450 is 2 + 1 = 3.
d. 15341 % 41 = 7 The address for key 15341 is 7 +1 = 8.

P13-4.In the midsquare hashing method, the key is squared and the address is selected from the
middle of the result. Use this method to select the address from each of the following keys. Use
digits 3 and 4, counting from the left. a. 142 b. 125 c. 134 d. 153

My solution:
To use the midsquare hashing method to select the address from each key, we need to follow
these steps: Square the key. Extract the middle two digits from the squared value. Use the
extracted digits as the address.
a. 142 squared is 20164. The middle two digits are 16, so the address for key 142 is 01.
b. 125 squared is 15625. The middle two digits are 56, so the address for key 125 is 56.
c. 134 squared is 17956. The middle two digits are 95, so the address for key 134 is 79.
d. 153 squared is 23409. The middle two digits are 34, so the address for key 153 is 34.
P13.5. In the fold shift hashing method, the key is divided into parts. The parts are added to obtain
the address. Use this method to find the address from the following keys. Divide the key into two-
digit parts and add them to find the address. a. 1422 b. 1257 c. 1349 d. 1532

My solution:
To use the fold shift hashing method, we divide the key into two-digit parts and add them
together. If the sum is larger than the table size, we take the remainder after dividing by the
table size. Let's assume the table size is 100.
a. Key 1422: Divide into two-digit parts: 14, 22 Add the parts: 14 + 22 = 36 Find the remainder
after dividing by the table size: 36 % 100 = 36 So the address for key 1422 is 36.
b. Key 1257: Divide into two-digit parts: 12, 57 Add the parts: 12 + 57 = 69 Find the remainder
after dividing by the table size: 69 % 100 = 69 So the address for key 1257 is 69.
c. Key 1349: Divide into two-digit parts: 13, 49 Add the parts: 13 + 49 = 62 Find the remainder
after dividing by the table size: 62 % 100 = 62 So the address for key 1349 is 62.
d. Key 1532: Divide into two-digit parts: 15, 32 Add the parts: 15 + 32 = 47 Find the remainder
after dividing by the table size: 47 % 100 = 47 So the address for key 1532 is 47.

13-6. In the fold boundary hashing method, the key is divided into parts. The left and right parts are
reversed and added to the middle part to obtain the address. Use this method to find the address
from the following keys. Divide the key into three two-digit parts, reverse the digits in the first and
the third part, and then add the parts to obtain the address.
a. 142234 b. 125711 c. 134914 d. 153213

My solution:
To use the fold boundary hashing method, we divide the key into three two-digit parts, reverse
the digits in the first and the third part, and then add them to the middle part. If the sum is
larger than the table size, we take the remainder after dividing by the table size. Let's assume
the table size is 100.
a. Key 142234: Divide into three two-digit parts: 14, 22, 34 Reverse the first and third parts: 41,
22, 43 Add the parts: 41 + 22 + 43 = 106 Find the remainder after dividing by the table size: 106
% 100 = 6 So the address for key 142234 is 6.
b. Key 125711: Divide into three two-digit parts: 12, 57, 11 Reverse the first and third parts: 21,
57, 11 Add the parts: 21 + 57 + 11 = 89 Find the remainder after dividing by the table size: 89 %
100 = 89 So the address for key 125711 is 89.
c. Key 134914: Divide into three two-digit parts: 13, 49, 14 Reverse the first and third parts: 31,
49, 41 Add the parts: 31 + 49 + 41 = 121 Find the remainder after dividing by the table size: 121
% 100 = 21 So the address for key 134914 is 21.
d. Key 153213: Divide into three two-digit parts: 15, 32, 13 Reverse the first and third parts: 51,
32, 31 Add the parts: 51 + 32 + 31 = 114 Find the remainder after dividing by the table size: 114
% 100 = 14 So the address for key 153213 is 14.
13-7. Find the address of the following keys using the modulo division method and a file of size 411.
If there is a collision, use open addressing to resolve it. Draw a figure to show the position of the
records. a. 10278 b. 08222 c. 20553 d. 17256

My solution:
To use the modulo division method, we divide the key by the file size and take the remainder as
the address. If there is a collision, we can use open addressing to find the next available slot.
Let's assume we have a file of size 411.
a. Key 10278: Address = 10278 % 411 = 3 There is no collision, so we can store the record at
address 3 + 1 = 4.
b. Key 08222: Address = 08222 % 411 = 2There is no collision, so we can store the record at
address 2 + 1 = 3
c. Key 20553: Address = 20553 % 411 = 2 There is collision, so we can store the record at address
3+1+1=5
d. Key 17256: Address = 17256 % 411 = 405 There is a no collision, so we can store the record at
address 405 + 1 = 406.

13-8.Redo P13-7 using linked list resolution

My solution:
To resolve collisions using linked list resolution, we can create a linked list at each slot in the
hash table to store all the records that hash to the same address. If there is a collision, we can
append the record to the linked list at that slot. Let's redo problem P13-7 using linked list
resolution. We have a file of size 411, and the following keys to store:
a. Key 10278: Address = 10278 % 411 = 3 There is no collision, so we can store the record at
address 3.
b. Key 08222: Address = 08222 % 411 = 69 There is no collision, so we can store the record at
address 69.
c. Key 20553: Address = 20553 % 411 = 2 There is no collision, so we can store the record at
address 2.
d. Key 17256: Address = 17256 % 411 = 405 There is a no collision, so we can store the record at
address 405.

You might also like