Slide 9
Slide 9 text
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 9
More Efficient Bubble sort
• Notice that after the 1st pass, the largest element is
placed in its final position (right most location).
• That indicates that after the 2nd pass, the second
largest element will be placed in its final position
and so on.
• So we can reduce the number of comparisons by 1
for every pass.
• If we have n elements in the array, then the 1st pass
requires (n-1) comparisons, the second pass
requires (n-2) comparisons, and so on.