Sorting and recursion

In class exercises
Change into your inclass directory.
[~]$ cd
[~]$ cd cs21/inclass/
If the w09-recursion directory does not yet exist, create it using mkdir
[inclass]$ mkdir w09-recursion
Copy the sample files for today from my directory using cp
[inclass]$ cp ~adanner/public/cs21/w09-recursion/* w09-recursion/
[inclass]$ ls
w01-intro/  w02-numAndString/  w03-decisions/ w04-graphics/
w05-functions/ w06-loops/ w09-recursion/
[inclass]$ cd w09-recursion/
[w09-recursion]$ ls
binarySearch.py
[w09-recursion]$ 
Sorting
Today we are going to write a function selectSort that sorts a list of numbers in place using an algorithm called selection sort. The basic idea of selection sort is to repeatedly find the next smallest element and place it in the correct position in the list by swapping. For example, we first find the smallest element in the list and place it in the first position of the list. Next we find the second smallest (this will be the smallest in the rest of the list, ignoring the first position). After repeating this process n times, where n is the length of the list, the list will be sorted.

Write a function swap(ls, i, j) that swaps the items in positions i and j in the list ls. We will use this function to implement selectSort(ls).

How many steps does this take? How much longer would selection sort take if we doubled the size of the list?

Recursion
Open binarySearh.py in vim.