Sorting in Data Structure, is a technique to rearrange the elements of a list in ascending or descending order, which can be numerical, lexicographical, or any user-defined order. Sorting is a process through which the data is arranged in ascending or descending order. Sorting can be classified in two ways:
This method uses only the primary memory during sorting process. All data items are held in main memory and no secondary memory is required this sorting process. If all the data that is to be sorted can be accommodated a time in memory is called internal sorting. There is a limitation for internal sorting, they can only process relatively small lists due to memory constraints. There are 3 types of internal sorts.
Sorting large amount of data requires external or secondary memory. This process uses external memory such as HDD, to store the data which is not fir into the main memory. So, primary memory holds the currently being sorted data only. All external sorts are based on process of merging. Different parts of data are sorted separately and merged together.