This preview shows page 1. Sign up to view the full content.
Unformatted text preview: 3. Insert 39 2. Insert 90 S. 1. 1. Insert 80 4. Insert 49 5. Insert 68 6. Insert 65 7. Input 100, Output 39 9. Input 120, Output 65 8. Input 15, Output 49 10. Input 25, Output 68 11. Input 35, Output 80 12. Input 130, Output 90 After all, we will merge the newly created queue with the old one by outputting the top records one after another. In this way, we will have these records in sorted order. S a l i m Sarımurat – 2 0 6 0 1 4 5 6 – H W # 3  3 S. 2. Without merging the file, the cost will only be reading and writing the file in 10 MB segments. Let b be the number of blocks in the file. 2 × b × ebt = 2 × 10 MB
× 0.84 = 2800 sec 6 S. 3. Assuming 10 MB is about 10,000,000 bytes, the number of segments in the file; nsg = 10 MB × 400
= 400 segments 10 MB We already know that 2800 seconds passed in heapsort. So, we are only expected to calculate the merging time. As we know, the number of passes needed is calculated by; ⎣log P (nsg )⎦ a. 2‐way merge Number of passes = ⎣log 2 (400 )⎦ = 9 Passing time = 9 × [2 × P × nsg × (s + r ) + 2 × b × ebt ] 10 MB
⎡
⎤
= 9 × ⎢2 × 2 × 400 × (24.3) + 2 ×
× 0.84⎥ = 25, 550 seconds 6
⎣
⎦ So, total time for2‐way merging is; 25, 550 seconds + 2800 seconds = 28,350 seconds b. 4‐way merge Number of passes = ⎣log 4 (400 )⎦ = 5 Passing time = 5 × [2 × P × nsg × (s + r ) + 2 × b × ebt ] 10 MB
⎡
⎤
= 5 × ⎢2 × 4 × 400 × (24.3) + 2 ×
× 0.84⎥ = 14, 389 seconds 6
⎣
⎦ So, total time for2‐way merging is; 14, 389 seconds + 2800 seconds = 17, 189 seconds S a l i m Sarımurat – 2 0 6 0 1 4 5 6 – H W # 3  4 c. P‐way merge We have 400 segments, so P = 400 in this part. Number of passes = ⎣log 400 (400 )⎦ = 1 Passing time = 1 × [2 × P × nsg × (s + r ) + 2 × b × ebt ] 10 MB
⎡
⎤
= 1 × ⎢2 × 400 × 400 × (24.3) + 2 ×
× 0.84⎥ = 10, 576 seconds 6
⎣
⎦ So, total time for2‐way merging is; 14, 389 seconds + 2800 seconds = 13, 376 seconds S. 4. 1. Insert 30 4. Insert 27 3. Insert 32 2. Insert 10 5. Insert 5 6. Insert 18 a. 3 disk accesses are needed. We will first access 30, then 28, and then 18. S a l i m Sarımurat – 2 0 6 0 1 4 5 6 – H W # 3  5 b. We will divide the total number of accesses required for each record with the total number of records to find the average. Let n be the number of records in the hash table. The average number of disk access required for successful search is; n ∑ (numberOfDiskAccessTo Re trieve) i i =0 n = 1+ 2 + 3 +1+1+ 2
= 1. 6 6 c. Using the same ideology, the number of accesses for an unsuccessful search; 3 +1+ 2
= 2 3 S. 5. We are expected to calculate the place of the records using mod (key, 31) hash function, so the pseudo keys and binary values of the given records will be the same because they are less than 2^31 value. First thing we are going to do is to calculate the binary values of the given records. 10 = 1010 7 = 111 17 = 10001 16 = 10000 20 = 10100 13 = 1101 21 = 10101 22 = 10110 3 = 11 14 = 1110 25 = 11001 30 = 11110 Then we will insert these records into hash table. 1. Insert 10 2. Insert 20 6. Insert 14 5. Insert 13 4. Insert 7 3. Insert 3 7. Update table 8. Insert 17 9. Insert 21 10. Update Table 11. Insert 25 12. Insert 16 13. Update table 14. Insert 22 15. Insert 30 After updating for the last time, the latest table becomes; S. 6. a. When bv = 5 and h = 5; Number of blocks hashed at level h = 27 Number of blocks hashed at level h +1 = 10 = 100100 The binary address of the last bucket of the file The binary address of the last bucket of the file hashed at level 5 = 11111 b. When bv = 0 and h = 5; Number of blocks hashed at level h = 32 Number of blocks hashed at level h +1 = 0 = 11111 The binary address of the last bucket of the file The binary address of the last bucket of the file hashed at level 5 = 11111 S a l i m Sarımurat – 2 0 6 0 1 4 5 6 – H W # 3  8 S. 7. We should first find the binary keys of records including their pseudo keys. Binary Keys Pseudo Keys 27 = 11011 18 = 10010 29 = 11101 28 = 11100 42 = 101010 13 = 1101 16 = 10000 27 = 0101 18 = 0111 29 = 0111 28 = 0110 42 = 1001 13 = 0010 16 = 0101 Then we will insert the records using these pseudo key values. 1. Insert 27, 18 and 29 2. Update the table to have more spaces for the coming records. 3. Insert 28, 42, 13 and 16 successively S a l i m Sarımurat – 2 0 6 0 1 4 5 6 – H W # 3  9 S. 8. We have already found the binary values in Q. 7. What we will do here is to insert the record with the given order using those key values. 1. Insert 27, 42, 18 2. Update table and insert 29 4. Insert 28, 13, 16 3. Update table As it is seen, the resulting table is not changed. However, we need some extra space in memory for 2nd step of the 8th question. ...
View
Full
Document
This note was uploaded on 12/01/2011 for the course CS 351 taught by Professor Fazlıcan during the Spring '11 term at Bilkent University.
 Spring '11
 FazlıCan

Click to edit the document details