(38 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 |

- Bubble Sort Algorithm in Python [401 Views]
- Pseudocode for Insertion Sorting [599 Views]
- Binary Tree Program implementation in C++ [180 Views]
- Simple Bubble Sort Algorithm in Java [445 Views]
- Depth First Search (DFS) Pseudocode and Program in Java [208 Views]

- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [10126 Views]
- Algorithm to find whether number is Armstrong Number or Not [9474 Views]
- How To Win Ludo King Game Every Time [9415 Views]
- error: Multiple commands produce error in Xcode 10 [5659 Views]
- FlowChart and Algorithm to find Whether a Number is Even or Odd [5123 Views]