{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 18 - Bubble Sort

# Lecture 18 - Bubble Sort - – Each time ﬁnd the bottom...

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

18 Bubble Sort Nov. 16, 2006 Announcements • Code log 3 appearing tonight. • Next Week (week 11): – Labs are all advising times (no structured lab material). – Extra advising hours on web-site Sunday. – Last week of quizzes (no quizzes in week 12) – A5 due: Thursday at noon! Announcements (cont.) • Week 12: – No labs. – No quizzes. – Exam review. • Exam: 14 – Dec – 2006 (Thursday) 7:00pm – 9:00pm 283 seats A/C A-U Odd Last Time • Arguments: – int main( int argc, char **argv ) – argc ~ number of arguments in the array argv – array ~ array of strings – argv[0] ~ program’s name Last Time (cont.) • Bubble Sort: – practical example Bubble Sort • Sort the top 2 elements of the array, then the top 3, then the top 4, ….

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

View Full Document
This is the end of the preview. Sign up to access the rest of the 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

{[ snackBarMessage ]}

### Page1 / 2

Lecture 18 - Bubble Sort - – Each time ﬁnd the bottom...

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

View Full Document
Ask a homework question - tutors are online