Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

BUBBLE SORT

8 5 9 3 (4 numbers)

Total 4 Numbers
So total number of passes to execute = 4-1 = 3
Pass 1:
Compare 1 & 2nd numbers

8>5 (Swapping)
5 8 9 3
Compare 2 & 3 rd numbers in the list
8>9 (False - no swap)
5 8 9 3
Compare 3rd and 4th number in the list
9>3 (swapping)
5 8 3 9
Pass 2:

Final output at Pass 3 (n-1)


3 5 8 9

You might also like