Sorting algorithms - Bubble Sort


Sorting is the process of arranging the elements of a sequence in ascending or descending order based on their numerical value.

Some of the mostly used basic sorting algorithms are as follows:

1. Bubble Sort

2. Insertion Sort

3. Selection Sort

Bubble sort


Bubble sort uses compare and exchange method while sorting as in each iteration, it compares the adjacent elements of the sequence and if the condition for ascending or descending order is not satisfied, the positions of these elements are exchanged. Each iteration places at least 1 element at its desired position.

This process is repeated until all elements are at the correct position.

Here is the visualisation of Bubble sort:


Implementation of bubble sort is as follows:

Time Complexity : O( n2 )

Output


So that’s it for this article we will be coming up with our next article on further topics very soon till then keep learning, keep coding, keep reading and keep improving !!



Happy Coding 😊

By Programmers Army