Presentation is loading. Please wait.

Presentation is loading. Please wait.

External Sort Any sort algorithm which uses external memory, such as tape or disk, during the sort. The best algorithms for processing large amounts of.

Similar presentations


Presentation on theme: "External Sort Any sort algorithm which uses external memory, such as tape or disk, during the sort. The best algorithms for processing large amounts of."— Presentation transcript:

1 External Sort Any sort algorithm which uses external memory, such as tape or disk, during the sort. The best algorithms for processing large amounts of data often differ from the best main memory algorithms for the same problem.

2 Two-Phase Multiway Merge-Sort
This algorithm for sorting is capable of sorting enormous amounts of data on disk using only two disk reads and two disk writes of each datum. Phase 1: Sort main-memory-sized pieces of data to form a number of sorted sublists. Phase 2: Merge all the sorted sublists into a single sorted list.

3 Phase 1: Sort Fill all available main memory with blocks from the original file to be sorted. Sort the records that are in main memory, using an appropriate main-memory sorting algorithm such as Quicksort. Write the sorted records from main memory onto new blocks of a disk file, forming one sorted sublist.

4 Phase 2: Merge Read the first block of each sorted sublist into a main-memory buffer, and use a buffer for the output block of the resultant list. Find the smallest among the first remaining elements of all the sublists and move it to the output block. If the output block is full, write it to disk and reinitialize the same buffer to hold the next output block. If the block from which the smallest element was just taken is now exhausted, read the next block of that sublist into the same buffer.

5 Extension of Multiway Merging
The number of available buffer blocks is M. The block size is B bytes. Two-Phase the maximal size of the file that can be sorted is equal to M(M-1)B bytes, or approximately M2B bytes. k-Phase approximately MkB bytes.


Download ppt "External Sort Any sort algorithm which uses external memory, such as tape or disk, during the sort. The best algorithms for processing large amounts of."

Similar presentations


Ads by Google