# What is Sorting

By | May 3, 2020

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

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.