What is Sorting

    What is Sorting? In Sorting Algorithms, we arrange the elements in a specific order it could be ascending or descending. We apply sorting algorithms on those data structures which are iterable, and most often which contain numeric data types. Though the sorting could be in any order, often we ordered our data structures element into numerical or lexicographical order. We sort our elements, so our elements stored in an organized way and it will optimize the working load of searching algorithms. The more the elements are sorted the less effort by the computer to locate the elements. Another advantage of sorted elements, they become more readable. There are many real-world examples such as a telephone dictionary, language dictionary, etc. all the data in the dictionary arranged in a specific order which makes it easy to use a dictionary and we can search what we want in a minute.

    In-Place and Not in-place

    There are many types of basic sorting algorithms such as bubble sort, merge sort, selection sort, shell sort, etc. In some of the sorting algorithms, we use extra array and variables to store the values of an array, such as temporary variable or array, and these types of sorting algorithms known as not in-place sorting . Merge sort is an example of not in-place sorting algorithms. In In-place sorting algorithms, we do not require any extra space to hold temporary values, these algorithms are capable to sort the complete array without any extra temporary variable all the operation occurs in the array itself.

    Types of Sorting

    1. Stable

    If an array contains two similar values and after applying the sorting algorithm those two values did not change their order of sequence then it would be termed as stable sorting. For example Before sorting: [2, 3, 4 , 5, 6, 4 , 7] After sorting: [2, 3, 4 ,  4, 5,  6, 7]

    2. Unstable

    In unstable sorting, the two elements having the same value change their order of sequence in the array after applying the sorting algorithm it will be known as unstable sorting. For example Before sorting: [2,3, 4 ,5,6, 4 ,7] After sorting: [2,3 4 , 4 ,5, 6,7]

    Types of Sorting algorithms

    1. Adaptive

    Those sorting algorithms which do not waste their time on sorted elements and use their all resource to sort the unsorted elements are known as Adaptive sorting algorithms.

    2. Non-Adaptive

    A Non-Adaptive Sorting Algorithm does not care if the array is already sorted or not it will apply its all resources to sort the sorted elements.

    Types of Sorting orders

    There are some specific order terms we use while applying the sorting algorithms.

    • Increasing Order: In Increasing Order sorting the next element is greater of the current one
    • Decreasing Order: In Decreasing Order sorting the next element is smaller of the current one.
    • Non-Increasing Order: In Non-Increasing Order, the next element is small or equal to the current one.
    • Non-Decreasing Order: In Non-Decreasing Order, the next element is greater or equal to the current one.

    People are also reading: