Practical Consideration of Internal Sorting and External
Practical Consideration of Internal Sorting and External
CONSIDERATION OF
INTERNAL AND
EXTERNAL SORTING
• Concept of Sorting
• Concept of Internal Sorting
• Practical consideration of Internal Sorting
• Concept of External Sorting
• Practical consideration of External Sorting
• Conclusion
SORTING
•EXAMPLE:
Let us consider there are 10,000 records which have
to be sorted. For this, we need to apply the external
merge sort method. Suppose the main memory has a
capacity to store 500 records in a block, with having
each block size of 100 records
External Merge Sort Practical Example
ALGORITHM
MergeSort(arr[], l, r)
If r > l
1. Find the middle point to divide the array into two
halves: middle m = (l+r)/2
2. Call mergeSort for first half: Call mergeSort(arr,
l, m)
3. Call mergeSort for second half: Call
mergeSort(arr, m+1, r)
4. Merge the two halves sorted in step 2 and 3: Call
merge(arr, l, m, r)
TWO WAY MERGE
SORT(cont.)
Multi-way Mergesort
Algorithm:
1. As before, read M values at a time into internal
memory, sort, and write as runs on disk
2. Merge K runs:
• Read first value on each of the k runs into
internal array and build min heap
• Remove minimum from heap and write to disk
• Read next value from disk and insert that value
on heap
Repeat steps until all first K runs are processed
Repeat merge on larger & larger runs until have
just one large run: sorted list
Multi-way Mergesort (cont.)