Lecture 18 - Bubble Sort

Lecture 18 - Bubble Sort - Each time nd the bottom element...

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

View Full Document Right Arrow Icon
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, ….
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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

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.

Page1 / 2

Lecture 18 - Bubble Sort - Each time nd the bottom element...

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