Skip to main content
External Sorting
By
V.Jothi lakshmi
External Sorting
• All the algorithms that we have learnt still
requires the input to be fit into main memory.
• There are some applications where the input
is too large to fit into main memory.
• To solve this problem external sorting
algorithms which are designed to handle very
large inputs.
Need of new algorithms
• Users usually want data sorted.
• Sorting useful for eliminating duplicates.
• Internal sorting algorithms take advantage of the fact
that memory is directly addressable.
• Shell sort – A[i] and A[i-hk] in one time unit
• Heap sort -- A[i] and A[i*2+1] in one time unit
• Quick sort -- 3 median of 3 partitioning
 A[left]
A[center]
A[right]
Need of new algorithms
• If input on tape – all these operations lose their
efficiency.
• Elements on tape can be accessed -sequent
• If it is in disk- lose of efficiency –delay required
to spin the disk and move the disk head.
Need of new algorithms
• To see how external accesses really are
 create a random file that is large.
But not too big to fit in main memory.
Read the file and sort using efficient algorithm.
Time to sort input compared to time to read input.
Even though sorting is an O(N log N) operation and
reading O(N)
Need of new algorithms
• To see how external accesses really are
 create a random file that is large.
But not too big to fit in main memory.
Read the file and sort using efficient algorithm.
Time to sort input compared to time to read input.
Even though sorting is an O(N log N) operation and
reading O(N)