What is Sorting

By | September 10, 2019

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 telephone dictionary, language dictionary, etc. all the data in dictionary arranged in a specific order which make easy to use a dictionary and we can search what we want in a minute.

In-Place and Not in-place Sorting

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 occur in the array itself.

Stable and Unstable Sorting:

Stable Sorting:

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]

Unstable Sorting:

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]

Adaptive and Non-Adaptive algorithms:

Adaptive Sorting Algorithms:

 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.

Non-Adaptive Sorting Algorithms:

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 of the current one.
  • Non-Decreasing Order: In Non-Decreasing Order, the next element is greater or equal of the Current one.

Leave a Reply

Your email address will not be published. Required fields are marked *