# What is meant by sorting ?

To arrange data in perfect order is called sorting, there are different approaches to solve them. by sorting the data it will be easier to search for them and we use them in our daily life.

So, at first, I have so many ideas to write but I find out that I am interested in sorting techniques and those are widely used in algorithms to reduce complexity and every sorting technique has it’s own pros and cons we have to use them according to situation. I am going to talk about top 6 sorting techniques which are used widely.

# Bubble Sort

It is on of the easiest sorting technique and everybody starts with this sort because it will show us how sorting works which are simple and it works repeatedly swapping the elements if they are not in the correct order. It starts from first element and goes on until to the last element then some of the elements will be sorted and then revolution takes place until the array is sorted but it may take time and it can be optimized by stopping the algorithm if no swapping is done.

**Worst complexity****: **n²

So we can say that:

- The average time increases almost exponentially as the number of table elements increase.
- Larger data sets require more complex code and more memory.
- It is a simple sorting technique that sorts the items in a memory.

# Selection sort

It is quite simple algorithm when we compare to bubble sort this one is better.

selection sort is noted for its straightforwardness and has execution benefits over more muddled calculations in specific circumstances, especially where assistant memory is restricted.

The calculation isolates the information list into two sections: an arranged sub list of things which is developed from left to directly at the front (left) of the rundown and a sub list of the excess unsorted things that involve the remainder of the rundown. At first, the arranged sub list is vacant and the unsorted sub list is the whole info list. The calculation continues by tracking down the littlest (or biggest, contingent upon arranging request) component in the unsorted sub list, it with the furthest left unsorted component (placing it in arranged request), and moving the sub list limits one component to one side.

**Worst complexity****: **n²

**Best complexity****: **n²

So we can say that:

- The main point is that this algorithm will do well on a small list than a larger list.
- similar to bubble sort it will also take n squared number of steps fo sorting n elements.
- It’s performance is easily influenced by the initial ordering of the items before the sorting process.

# Insertion sort

Insertion sort is a basic arranging calculation that forms the last arranged sorted array or list each thing in turn. It is significantly less effective on enormous records than further developed calculations, for example, merge sort, heapsort, or quicksort. Insertion sort repeats, devouring one information component every reiteration, and grows an arranged yield list. At every emphasis, inclusion sort eliminates one component from the information, finds the area it has a place inside the arranged rundown, and supplements it there. It rehashes until no info components remain.

**Worst complexity****: **n²

So we can say that :

- This sorting technique uses minimal amount of space.
- With n-squared steps required for every n element to be sorted.
- This technique is particularly used when there are low number of elements in a list.

# Merge Sort

From now on the difficulty level increases. It is a perfect example for divide and conquer algorithm because in this sorting technique we divide the whole array into a single part and then checks each and part whether which is bigger or smaller then it compares them and swap their places after sorting two elements then they are compared with the next two elements and then after sorting them they conquer and al last all of the elements in the array or list will be sorted.

**Worst complexity****: **n*log(n)

**Average complexity****: **n*log(n)

**Best complexity****: **n*log(n)

So we can say that:

- It can be used for any size of array or list.
- If heap sort is used for the in-memory part of the merge, its operation can be overlapped with I/O.
- merge sort required more space then other sorting technique.

# Quick Sort

It is also going to use divide and conquer method like merge sort. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quick Sort that pick pivot in different ways and it is bit more complicated. This algorithm have mainly three steps. First we need to select a pivot element in the array we can pick any element. Second move all the elements to the left of the pivot when the element is smaller than that and move the element to right side of pivot if the element is larger than pivot. Third step, recursively call the above two steps for the subarrays of the element with smaller and bigger elements then the pivot.

**Worst complexity****: **n²

**Average complexity****: **n*log(n)

**Best complexity****: **n*log(n)

So we can say that:

- This algorithm widely used when we have huge amount of elements.
- Because it sorts in exact place where it was divided, no additional storage is required as well.
- All elements in the first sub list are arranged to be smaller than the pivot.

So at last I want make a conclusion that these are not only the sorting technique used. By reading my blog you can get a basic idea of what is sorting and what are the basics in it. when you go deeper into sorting you may get a question that which algorithm is used in which condition and what is the criteria to use them by practicing these techniques and gaining experience you will be familiar with these and you will get to know where to use which sorting technique.