bubble-sort - CSE 380 Bubble Sort What is Bubble Sort?...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 380 Bubble Sort What is Bubble Sort? Simple algorithm for sorting values in a list How Does Bubble Sort Work? The list is repeatedly traversed, comparing two consecutive positions at a time, and swapping the values in the two positions if the first is larger than the second On each successive pass on the list, one less position needs to be looked at since the highest value high has migrated to the end of the list ± On the first pass. .. ² The entire list is traversed ² The highest migrates to the end of the list ± On the second pass… ² The last element does not need to be compared ² Afterward, the last two positions contain the highest two values ± On the third pass… ² The last two elements don’t need to be compared ² Afterward, the last three positions contain the highest three values ± Finally, on the last pass… ² Only the first two elements are looked at ² Afterward, the entire list is sorted Example Sort the word BUFFALO B B B B B B B B B B B B B B B Data
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/03/2011 for the course CSE 380 at SUNY Buffalo.

Page1 / 2

bubble-sort - CSE 380 Bubble Sort What is Bubble Sort?...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online