be equal to the size of the list 3.For each element in the list: 1.Add its value to count 4.Divide count by sum Find the mean of a list of numbers: Thursday, July 26, 12

sorting is foundational to many algorithms. In general, you should defer to the standard library sorting implementations for your language. But understanding and thinking about sort is valuable. Thursday, July 26, 12

) repeat swapped = false for i = 1 to length(A) - 1 inclusive do: /* if this pair is out of order */ if A[i-1] > A[i] then /* swap them and remember something changed */ swap( A[i-1], A[i] ) swapped = true end if end for until not swapped end procedure http://en.wikipedia.org/wiki/Bubble_sort Thursday, July 26, 12

) repeat swapped = false for i = 1 to length(A) - 1 inclusive do: /* if this pair is out of order */ if A[i-1] > A[i] then /* swap them and remember something changed */ swap( A[i-1], A[i] ) swapped = true end if end for until not swapped end procedure http://en.wikipedia.org/wiki/Bubble_sort Bubble sort is O(?) Thursday, July 26, 12

) repeat swapped = false for i = 1 to length(A) - 1 inclusive do: /* if this pair is out of order */ if A[i-1] > A[i] then /* swap them and remember something changed */ swap( A[i-1], A[i] ) swapped = true end if end for until not swapped end procedure http://en.wikipedia.org/wiki/Bubble_sort Bubble sort is O(n2) Thursday, July 26, 12