Sorting is the operation of arranging the records of a table/list/array in a particular order, either in ascending or descending order.
While sorting we must take care of special case, when two or more records/elements/nodes have same key values then it is important to preserve the order of the elements/records/nodes.
A sorting algorithm is said to be stable if it preserves the order of the elements with duplicate values.
If all the records to be sorted are kept internally in the main memory while sorting then the sort is said to be internal sort.
If there are large numbers of elements to be sorted then while sorting process all the elements cannot be kept in the main memory but are stored in the secondary storage device, this kind of sorting is termed as external sorting.
Difference between internal and external sorting
|Internal sorting||External sorting|
|Internal sorting is done in internal memory||External sorting in done in external memory|
|Internal sorting is applied to a smaller collection of data||External sorting is applied to huge collection of data.|
|Internal sorting does not make use of extra resources.||External sorting makes use of extra resources.|
|Internal sorting requires primary memory such as RAM.||External sorting requires primary memory such as floppy disk , hard disk, etc.|
|Example: insertion sort , quick sort.||Example: merge sort.|