225_10_maxSort_proofs

225_10_maxSort_proofs -...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Our midterm is Tues. Oct. 18 (the course outline has been  revised to have this new date). Start work on Assignment #2 early so you can ask for help  if you need it. Mon. Oct. 10: Thanksgiving, no lab this week. Assignment 2 Part A: Due Wed. Oct. 12 Assignment 2 Part B: Due Fri. Oct. 14
Background image of page 2
3 public void maxSort(int size) {      int i, t, maxPos;            if (size <= 1) return;          maxPos=0;        for (i=1; i < size; i++)              if ( A[i] >= A[maxPos]   ) maxPos=i;         t= A[maxPos];        A[maxPos]= A[size-1];        A[size-1] = t;        maxSort(size-1);    }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Prove by induction: maxSort does n(n-1)/2  key comparisons  on a problem of  size n.
Background image of page 4
Basis (n=0): 0*(0-1)/2=0 so the base case holds.  [Induction step] Assume 1+2+ … + (n-1)= n(n-1)/2. We want to prove that 
Background image of page 5

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

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

This note was uploaded on 01/15/2012 for the course CSC 225 taught by Professor Valerieking during the Spring '10 term at University of Victoria.

Page1 / 12

225_10_maxSort_proofs -...

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

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