Solutions to homework 1

advertisement
Solutions to homework 1
10.8. Consider the deletion of record 5 from the file of Figure 10.8. Compare the relative
merits of the following techniques for implementing the deletion:
(a) Move record 6 to the space occupied by record 5, and move record 7 to the space
occupied by record 6.
(b) Move record 7 to the space occupied by record 5.
(c) Mark record 5 as deleted, and move no records.
Ans.: (a) It is the most straightforward approach. It preserves ordering and prevents
fragmentation of space, but requires moving the most records and involves the most accesses.
(b) It moves fewer records and prevents fragmentation of space, but destroys any ordering in the
file and may require one more disk block access.
(c) It preserves ordering and moves no records, but requires additional overhead to keep track of
all the free space in the file and records are no longer stored contiguously.
10.9. Show the structure of the file of Figure 10.9 after each of the following steps:
(a) Insert (Brighton, A-323, 1600)
(b) Delete record 2.
(c) Insert (Brighton, A-626, 2000).
Ans.: (a)
header
record 0
Perryridge
A-102
400
record 1
Brighton
A-323
1600
record 2
Mianus
A-215
700
record 3
Downtown
A-101
500
Perryridge
A-201
900
record 7
Downtown
A-110
600
record 8
Perryridge
A-218
700
record 4
record 5
record 6
1
(b)
header
record 0
Perryridge
A-102
400
record 1
Brighton
A-323
1600
Downtown
A-101
500
Perryridge
A-201
900
record 7
Downtown
A-110
600
record 8
Perryridge
A-218
700
record 0
Perryridge
A-102
400
record 1
Brighton
A-323
1600
record 2
Brighton
A-626
2000
record 3
Downtown
A-101
500
Perryridge
A-201
900
record 7
Downtown
A-110
600
record 8
Perryridge
A-218
700
record 2
record 3
record 4
record 5
record 6
(c)
header
record 4
record 5
record 6
10.12. Show the structure of the file of Figure 10.12 after each of the following steps:
(a) Insert (Mianus, A-101, 2800)
(b) Insert (Brighton, A-323, 1600)
(c) Delete (Perryridge, A-102, 400)
Ans.: (a)
0
Perryridge
A-102
400
A-201
900
A-218
700
1
Round Hill
A-305
350




2
Mianus
A-215
700
A-101
2800


3
Downtown
A-101
500
A-110
600


4
Redwood
A-222
700




5
Brighton
A-217
750




2
(b)
0
Perryridge
A-102
400
A-201
900
A-218
700
1
Round Hill
A-305
350




2
Mianus
A-215
700
A-101
2800


3
Downtown
A-101
500
A-110
600


4
Redwood
A-222
700




5
Brighton
A-217
750
A-323
1600


0
Perryridge
A-201
900
A-218
700


1
Round Hill
A-305
350




2
Mianus
A-215
700
A-101
2800


3
Downtown
A-101
500
A-110
600


4
Redwood
A-222
700




5
Brighton
A-217
750




(c)
10.13. What happens if you attempt to insert the record
(Perryridge, A-929, 3000)
into the file of figure 10.12 ?
Ans.: It causes an error because the record would exceed the maximum length reserved.
10.14. Show the structure of the file of figure 10.13 after each of the following steps:
(a) Insert (Mianus, A-101, 2800)
(b) Insert (Brighton, A-323, 1600)
(c) Delete (Perryridge, A-102, 400)
Ans.: (a)
0
Perryridge
A-102
400
1
Round Hill
A-305
350
2
Mianus
A-215
700
3
Downtown
A-101
500
4
Redwood
A-222
700
A-201
900
A-217
750
7
A-110
600
8
A-218
700
9
A-101
2800
5
6
Brighton
3
(b)
0
Perryridge
A-102
400
1
Round Hill
A-305
350
2
Mianus
A-215
700
3
Downtown
A-101
500
4
Redwood
A-222
700
A-201
900
A-217
750
7
A-110
600
8
A-218
700
9
A-101
2800
10
A-323
1600
5
6
(c)
Brighton
0
returned to free list
1
Round Hill
A-305
350
2
Mianus
A-215
700
3
Downtown
A-101
500
4
Redwood
A-222
700
5
Perryridge
A-201
900
6
Brighton
A-217
750
7
A-110
600
8
A-218
700
9
A-101
2800
10
A-323
1600
10.17. In the sequential file organization, why is an overflow block used even if there is, at the
moment, only one overflow record?
Ans.: Since a block is the smallest unit which can be read from the disk, using any smaller region
would not be useful from the performance standpoint. The space saved by allocating disk storage
in records units would be overshadowed by the performance cost of allowing blocks to contain
records of multiple files. Furthermore, the free space in the block can be used for future
insertions.
4
5
Download