Sorting in Data Structures

In this tutorial, we will study Sorting in Data Structures.

  • Sorting is a process of arranging the data into a particular order.
  • Definition: Arranging set of data in some kind of order is referred as sorting.
  • In sorting data is arranged in ascending or descending order.


Telephone directory names of persons arranged in alphabetical order.

Consider a simple example of sorting, We are having 5 random numbers as 10 2 19 1 8

As these are the random number we need to sort the number as, 1 2 8 10 19

We got the sorted list easily but how we sort these random numbers to be sorted. For this, there are various techniques available in a data structure which are different from each other and performed in the different fashion to arrange the data in particular order.

Different techniques of Sorting in Data Structures.

  1. Bubble sort
  2. Selection sort
  3. Insertion sort
  4. Merge sort
  5. Heap sort
  6. Quick sort
  7. Binary sort
  8. Shell sort
Different techniques of sorting

As above we are having different techniques for sorting these techniques has different time complexity.

Time complexity:-

The total time required for execution of a program is known as time complexity.

We will choose anyone sorting technique whose complexity will be suitable for your needs or we use sorting technique which is efficient.

Advantages of sorting

  1. It will make retrieving and traversing data easy and simple.
  2. It makes memory management easy.
  3. Sorting also makes searching easy.

Time complexity table:-

QuickO(n2)O(n log n)O(n log n)
MergeO(n log n)O(n log n)O(n log n)
BinaryO(n log n)O(n log n)O(n2)
RadixO(n2)O(n log n)O(n log n)
HipO(n log n)O(n log n)O(n log n)