(448 Views)

Bubble Sort is a simple sorting technique in which a given set of elements provided in form of an array are sorted by simple conversion. It compares all the elements one by one and sort them accordingly.

If sorting is to be done in ascending order, then bubble sort will start by comparing the first element with the second element, if the first element is greater than the second element, it will swap them, and then compare it with the second and the third element, and so on. With every complete iteration the largest element in the given array,is placed at the last place or the highest index

In the above algorithm,

- We first read the array from the user.
- We start by comparing the first element of the array with the second element, and in case if the first element is greater than the second element, we will swap both the elements, and then move on to compare the second and the third element, and continue till the end so on.
- If the first element is lesser than the second element then we move to the second and compare it with the third element and move so on.
- In case the is greater we follow the step 4 and if it'sless we follow step 5. Both of the are discussed above.
- We follow the same process until the given array is sorted.

0 UpvotesUpvote |
0 DownvotesDownvote |

- Python program for Selection Sort Algorithm [1120 Views]
- Depth First Search (DFS) Pseudocode and Program in Java [522 Views]
- Bubble Sort Algorithm implementation in Kotlin [850 Views]
- Linked List for Beginners [1412 Views]
- Binary Tree Program implementation in C++ [478 Views]

- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [23462 Views]
- How To Win Ludo King Game Every Time [23300 Views]
- Algorithm to find whether number is Armstrong Number or Not [21998 Views]
- Jio Phone hang on LOGO problem Solution - Hard Reset Jio Phone [14502 Views]
- error: Multiple commands produce error in Xcode 10 [12290 Views]