|
In this article:
- What is sorting
- What is a sorting algorithm
- Overview of common sorting algorithms
What is Sorting?
The process of arranging all or some items in a set of items in a particular order or sequence is called Sorting. Though sorting maybe of different types, the most important of them is the sorting of information in a pre-defined sequence which is often alphabetic. The result of the sorting process is a new list containing the same data as the older, unsorted list which are now arranged in ascending or descending order.
What is a sorting algorithm?
The step by step procedure or algorithm that arranges the elements of a given list in a desired order (say, ascending) is called a Sorting Algorithm. While sorting has the basic objective of arranging the given data, it may also be put to use by the algorithms for searching and merging of data which require a sorted list to work properly themselves. Sorting algorithms are commonly studied by students of computer science (and other courses) so as to get a touch of the core concepts of algorithms. However, in spite of the existing ones, new sorting algorithms are still being made.
Overview of common sorting algorithms
There are certain basic sorting algorithms that are known all around the world. These are explained in brief below:
- Bubble sort
This is a very popular sorting algorithm. It was first introduced in 1956. It is renowned for its simplicity and the ease with which it works. Under the bubble sort method, the first two elements in the list of items or the set are compared. If the first one is greater than the second one, they are swapped, that is, the first one is moved to the second position and the second one is moved to the first position in the list. This procedure continues till the end of the list is reached comparing each pair of consecutive elements. Once the end has been reached, the whole process is repeated from the top of the list (that is, the first element) until there is no swapping left to be done. Once this has been done, the resultant list is sorted in the desired order.
- Insertion sort
The insertion sort is another simple algorithm which is most apt for sorting small lists. Under this method, an item is picked up from the list and its correct position is found in the new list. It is then inserted at that point (and hence the name of the algorithm). Then, another item is taken from the list and by comparing it to other elements in the new list, its position is found and it is inserted in the new list while moving the elements in the list up or down the list as required. This continues till all the items from the older list have been placed in the new list hence giving the required ordered list.
- Merge sort
The merge sort is an algorithm that has been found to work efficiently even with larger list of items. Under this method, two sorted lists are merged into a single, common list. By comparing two corresponding elements, it swaps them to put them in order and then merges the two resulting lists. This is continued till all the elements have been compared and swapped as required and the last two lists are merged to form the desired sorted list.
- Quicksort
This is one of the fastest available algorithms today. The Quicksort algorithm takes a central value and partitions the array into two parts. The first part, that is, the one before this point, would contain the smaller elements while the other one would have the larger elements in it. The sub-lists that are hence formed are then sorted individually to give the final sorted list of elements or array. The Quicksort algorithm is a type of divide and conquer algorithm.
|