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

- Insertion Sort Algorithm Implementation in Java [927 Views]
- Depth First Search (DFS) Pseudocode and Program in Java [512 Views]
- Algorithm and Flowchart for Stack using Arrays [217 Views]
- AVL Tree Algorithm in Java [1152 Views]
- Heap Sort Algorithm in Java [1237 Views]

- Algorithm to find whether number is Armstrong Number or Not [40268 Views]
- How To Win Ludo King Game Every Time [39376 Views]
- Jio Phone hang on LOGO problem Solution - Hard Reset Jio Phone [27664 Views]
- Knuth-Morris-Pratt (KMP) Substring Search Algorithm with Java Example [27560 Views]
- FlowChart and Algorithm to find Whether a Number is Even or Odd [20062 Views]