Sorting

Sorting and its Importance


From this point on we will try to understand different methods of sorting and their importance. 

Sorting:

Sorting is any process which arranges the items in an ordered way.

Why Sort?

Sorting is mainly used for improving our data structure so that we can make our algorithm which we work on to give results faster, ultimately making our algorithm more better at its work. Aside from improving efficiency it is also used for structuring our data and cleaning our data. In a general sense "A sorted data is much easier to handle than an unsorted one".


Why do we need different sorting algorithms?

Well in simple terms, to have more tools available at our hand we can use whichever we need to sort easily or in a more efficient way to improve efficiency or simplicity of the program according to the need or priorities. i.e. To make sorting faster or more simpler, as per need.


Example on how sorting helps:

Suppose we have a list of unsorted numbers : 1,4,3,7,99,76,2,45,72
Assume that we need to look for the number 72, as the list is unsorted the number 72 can be in any position in the list.
Now lets take the same list, and sort it. : 1,2,3,4,7,45,72,76
now we need to find the same number 72, we can easily find it using binary search
i.e. 
compare(middle,toFindNumber);
if(toFindNumber > middle):
    repeatFromRight,discard left & itself
else
   repeatFromLeft, discard right and itself
till : number found or only one number remaining and is not equal.

when we use the above algorithm, we get 7<72 we discard till 7 from left.
then 72 = 72, we found the number. 

Suppose the list was very big, then doing a linear search would become hectic and inefficient, hence this example presents the significance of sorting.


Written by,
Sarvesh Bhatnagar

Popular Posts