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

635592013-python

The document contains a series of programming exercises related to file management and hashing methods. It includes tasks for updating a master file based on transaction data, creating an index file, and calculating addresses using modulo division and midsquare hashing techniques. Each exercise is accompanied by a student's solutions demonstrating the application of the concepts learned.

Uploaded by

rxmgdz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

635592013-python

The document contains a series of programming exercises related to file management and hashing methods. It includes tasks for updating a master file based on transaction data, creating an index file, and calculating addresses using modulo division and midsquare hashing techniques. Each exercise is accompanied by a student's solutions demonstrating the application of the concepts learned.

Uploaded by

rxmgdz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRESSTEST 2 - CSI

Name : Nguyen Le Dang Khoa


Class : se20a02
P 13-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
Departmen
Key Name
t
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:

Departmen
Key Name
t
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

P 13-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.
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.

You might also like