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
- Spring '06
- Bubble Sort, Analysis of algorithms, Computational complexity theory, – Labs, Best-case complexity, Average-case complexity