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.
The choice for which sorting method is suitable for a problem depends on several dependencies.
Configurations for different problems.
The most noteworthy of these considerations are:
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.
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.

Bubble Sort Algorithm

So, Bubble sort is a simple sorting algorithm.
Moreover, This sorting algorithm is a comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order.
Than, This algorithm is not suitable for large data sets as its average and worst-case complexity are of Ο(n2) where n is the number of items.

Bubble Sort Algorithm:

Moreover, In the bubble sort method, the list is divide into two sub-lists sort and unsorted.
at the last The smallest element is bubble from the unsorted sub-list.
Than, After moving the smallest element the imaginary wall moves one element ahead.
The bubble sort was originally written to bubble up the highest element in the list. But there is no difference whether the highest / lowest element is bubble.
This method is easy to understand but time-consuming. In this type, two successive elements are compared and swapping is done.
Thus, step-by-step entire array elements are checked. So, Given a list of ‘n’ elements the bubble sort requires up to n-1 passes to sort the dat

Bubble sort, Sorting algorithm

Bubble sort algorithm

Bubble_Sort ( A [ ] , N )

  1. Step 1 : Repeat For i = 0 to N – 1 Begin.
  2. Step 2 : Repeat For J = 1 to N – i – 1 Begin. S
  3. tep 3 : If ( A [ J ] < A [ J – 1 ] ) Swap ( A [ J ] , A [ J – 1 ] ) End For End For.
  4. Step 4 : Exit.

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

So, try it your self on online compiler.

# Bubble Sort
#include <stdio.h>
int main()
 int a[100], n, c, d, position, t;
 printf("Enter number of elements\n");
 scanf("%d", &n);
 printf("Enter %d integers\n", n);
 for (i = 0; i < n; i++)
 scanf("%d", &a[i]);
 for (i = 0; i <= n-1; i++) // finding maximum element (n-1) times
 for (j =1; j <= n – i - 1; j++)
 if (a[j] < a[j-1])
 t = a[j];
 a[j] = a[j-1];
 a[j-1] = t;

Leave a Reply

Your email address will not be published.