In Class: Week 9
Sorting


Run update21 to obtain this week's files in cs21/inclass/w09-sort.

Topics


In-class work

    Binary Search

  1. Binary search allows us to improve search efficiency on sorted lists. But how to we quantify this improved efficiency? We will analyze the algorithm to see that it has a big-O of lg N.

    Sorting

  2. In groups of 2 or 3, grab 8 playing cards. Give a random set of cards, think of possible algorithms for sorting the list of cards from smallest to lowest. Specifically, describe each comparison that needs to be done and when a swap of two cards takes place
  3. First, we will discuss the algorithm selection sort which, on the first step, searches the entire list for the minimum value. This value is swapped with position 0 in the list. On the next pass, the algorithm repeats the process for the remaining part of the list (position 1 to N-1).
  4. In sortNumbers.py, we will implement selection sort to put a a list of ints in order from smallest to largest
  5. How many steps does selection sort take in the worst case for a list of size N? How many compares does it it perform? How many swaps?
  6. Next, we will cover bubble sort, describe it's complexity, and implement it in our sortNumbers.py program.