External Sorting
Example of Two-Way Sorting:
N = 14, M = 3 (14 records on tape Ta1, memory capacity: 3 records.)
Ta1: 17, 3, 29, 56, 24, 18, 4, 9, 10, 6, 45, 36, 11, 43
Example of Two-Way Sorting:
N = 14, M = 3 (14 records on tape Ta1, memory capacity: 3 records.)
Ta1: 17, 3, 29, 56, 24, 18, 4, 9, 10, 6, 45, 36, 11, 43
- Sorting of runs:
- Read 3 records in main memory, sort them and store them on Tb1:
- Read the next 3 records in main memory, sort them and store them on Tb2
- Read the next 3 records in main memory, sort them and store them on Tb1
- Read the next 3 records in main memory, sort them and store them on Tb2
- Read the next 3 records in main memory, sort them and store them on Tb1
- Merging of runs B1. Merging runs of length 3 to obtain runs of length 6.
Tb1: 3, 17, 29
Tb2: 18, 24, 56
Tb1: 3, 17, 29, 4, 9, 10
Tb2: 18, 24, 56, 6, 36, 45
(there are only two records left)
Tb1: 3, 17, 29, 4, 9, 10, 11, 43
Tb1: 3, 17, 29 | 4, 9, 10 | 11, 43
Tb2: 18, 24, 56 | 6, 36, 45 |
Tb1: 3, 17, 29 | 4, 9, 10 | 11, 43
Tb2: 18, 24, 56 | 6, 36, 45 |
In the example we needed three passes (B1, B2 and B3) because [Log(14/3)] + 1 = 3.
No comments:
Post a Comment