This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Each time nd the bottom element to be sorted and bubble it upwards as long as it is smaller than the element above Bubble Sort Algorithm (NOT C code!) sort( array, array_size ) for (n=0;n<array_size;n++) bubble( n, array ) bubble( n, array ) while n>0 if array[n]<array[n-1] swap(array[n],array[n-1]) n = n-1; else return; Bubble Sort Simple, easy to understand O(n) best case complexity takes about a number of steps equal to the size of the array O(n 2 ) average case complexity takes about a number of steps equal to the size of the array squared O(n 2 ) worst case complexity take about a number of steps equal to the size of the array squared...
View Full Document
This note was uploaded on 04/17/2011 for the course CIS 1500 taught by Professor Kramer during the Spring '06 term at University of Guelph.
- Spring '06
- Bubble Sort