Introduction To Sorting: Practical Considerations For Internal Sorting
Introduction To Sorting: Practical Considerations For Internal Sorting
Introduction To Sorting: Practical Considerations For Internal Sorting
Sorting means arranging the elements of an array so that they are placed in some relevant order
which may be either ascending or descending. That is, if A is an array, then the elements of A are
arranged in a sorted order (ascending order) in such a way that A[0] < A[1] < A[2] < ...... < A[N].
A sorting algorithm is defined as an algorithm that puts the elements of a list in a certain order,
which can be either numerical order, lexicographical order, or any user-defined order. Efficient
sorting algorithms are widely used to optimize the use of other algorithms like search and merge
algorithms which require sorted lists to work correctly. There are two types of sorting:
Internal sorting which deals with sorting the data stored in the computer’s memory
External sorting which deals with sorting the data stored in files. External sorting is applied
As mentioned above, records can be sorted either in ascending or descending order based on a field
often called as the sort key. The list of records can be either stored in a contiguous and randomly
accessible data structure (array) or may be stored in a dispersed and only sequentially accessible
data structure like a linked list. But irrespective of the underlying data structure used to store the
records, the logic to sort the records will be same and only the implementation details will differ.
When analysing the performance of different sorting algorithms, the practical considerations
BUBBLE SORT
Bubble sort is a very simple method that sorts the array elements by repeatedly moving the
largest element to the highest index position of the array segment (in case of arranging
elements in ascending order). In bubble sorting, consecutive adjacent pairs of elements in the
array are compared with each other. If the element at the lower index is greater than the
element at the higher index, the two elements are interchanged so that the element is placed
before the bigger one. This process will continue till the list of unsorted elements exhausts.
This procedure of sorting is called bubble sorting because elements ‘bubble’ to the top of the
list. Note that at the end of the first pass, the largest element in the list will be placed at its
proper position (i.e., at the end of the list).