What is Sorting?

Sorting refers to arranging data in a particular format. The sorting algorithm specifies the way to.
arrange data in a particular order.
Sorting is nothing but storage of data in sorted order, Types of Sorting descending
Sorting arranges data in a sequence which makes searching easier.

Complexity of Sorting algorithm

The complexity of the sorting algorithm calculates the running time of a function in which ‘n’ number of items is to be sorting.
So, The choice for which sorting method is suitable for a problem depends on several dependencies.
Then, Configurations for different problems.
So, The most noteworthy of these considerations are:
Moreover, The length of time spent by the programmer in.
So, Programming a specific sorting program.
Then, the Amount of machine time necessary for running the program.
At the last, The amount of memory necessary for running the program.

Types of Sorting

  1. Selection Sort
  2. Bubble sort
  3. Insertion sort
  4. Quick Sort
  5. Shell Sort
  6. Merge Sort etc.

Shell Sort Algorithm

Shell sort is a highly efficient sorting algorithm and is based on an insertion sort algorithm.
Then, This algorithm avoids large shifts as in the case of insertion sort if the smaller value is to the far right and has to be moved to the far left.
This algorithm uses insertion sort on widely spread elements, first to sort them and then sorts the less widely spaced elements. So, This spacing is termed interval.
Then, This algorithm is quite efficient for medium-sized data sets as its average and worst-case complexity are of Ο(n), where n is the number of items.

gap= Floor(N/2) N: Number of element in list
• For example:
gap= floor(7/2)
Shell Sort Algorithm
Shell Sort Algorithm
Shell Sort Algorithm

Shell Sort Algorithm

Int shellSort(int arr[] , int n) {
 for( int gap = n / 2; gap > 0; gap = gap / 2 )
 for( int i = gap; i < n; i++ ) {
Int temp =arr[i];
int j;
 for(j=i ; j >= gap && arr[j - gap ] > temp ; j -= gap )
arr[ j ] = arr[ j - gap ];
 arr[ j ] = temp;

Then, Using C programming to perform this sorting operation you can follow any language.

So, try it your self on online compiler.

int shellSort(int arr[], int n) 
 // Start with a big gap, then reduce the gap 
 for (int gap = n/2; gap > 0; gap /= 2) 
// Do a gapped insertion sort for this gap size. // The first gap elements a[0..gap-1] are already in gapped order 
 // keep adding one more element until the entire array is // gap sorted 
 for (int i = gap; i < n; i += 1) 
// add a[i] to the elements that have been gap sorted // save a[i] in temp and make a hole at position i 
 int temp = arr[i]; 
 // shift earlier gap-sorted elements up until the correct // location for a[i] is found 
 int j; 
 for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) 
 arr[j] = arr[j - gap]; 
 // put temp (the original a[i]) in its correct location 
 arr[j] = temp; 
 return 0; 
void printArray(int arr[], int n) 
 for (int i=0; i<n; i++) 
 cout << arr[i] << " "; 
 int main() 
 int arr[] = {12, 34, 54, 2, 3}, i; 
 int n = sizeof(arr)/sizeof(arr[0]); 
 cout << "Array before sorting: \n"; 
 printArray(arr, n); 
 shellSort(arr, n); 
 cout << "\nArray after sorting: \n"; 
 printArray(arr, n); 
 return 0; 

Than, If you want to read more …….

so, visit our website and click here:-https://learningpoints.in/

And for more algorithm concept click on- Algorithm Archives – Learning Points

thank you for coming to our website please share with your friends And do comment

Thank you.

Leave a Reply

Your email address will not be published.