Sorting algorithms are explained in this article to implement them easily. Algorithm To Implement Bubble, Selection, Insertion & Radix/Bucket Sort is explained.
Sorting means bringing some orderliness in the data, which are otherwise not ordered. For example, to print the list of students in ascending order of their birth dates, we need to sort the student information in ascending order of date of birth (student information stored in a file may not be in this order) before generating the print report. In most of the computer applications we need to sort the data either in ascending or descending order as per the requirements of the application. Sorting techniques are broadly classified as internal sort techniques and external sort techniques.
Internal sort is also known as Memory Sort, and it is used to sort the small volume of data in computer memory. Following are the some of internal or memory sort techniques.
- Bubble sort
- Selection sort
- Insertion sort
- Bucket sort
- Radix sort
- Quick sort
- Merge sort
The term External sort is referred to sorting of voluminous data. For example, to create a temporary file sorted on some key from the input file containing thousands of records, we need to divide the input file in small partitions, which can be sorted on the key by using any one of the known internal sort techniques and then merging those partitions on the sorted key to generate new partition of bigger size and this process is repeated until we get only one large sorted partition of size equal to the number of records in input file. In practice most of the times it is not possible to bring the entire data from input file to the memory of computer for sorting and we have to use some secondary storage to store the intermediate results (partitions). Thus in external sort input and output sorted files are stored on secondary storage i.e. disk.