Week 3 - Sorting out our Sorting Algorithms

NOTE: I strongly encourage you to divide this week up into three study sessions

 

How? What?

Last week I asked you to examine and evaluate three sorting algorithms

 

To start with, I want to walk you through each of the three sorts and try to explain how they work

Bubble Sort

 

I'm not going to go into nearly the same level of detail with the other two sorts. Let's just convert them from psuedocode to python and then run them through PythonTutor. If you want to see paper walkthroughs for the pseudocode or talk to me about visualizing in Thonny, I will be happy to meet with you one-on-one and do this.

Insertion Sort

 

Selection Sort

Sort Efficiency

First of all, we want to consider, what is the Big-Oh notation for each of these three sorts.

 

You Try It

To wrap up this week there are two "sets" of activitities that I would like you to work on, preferably with a partner

  1. Consider how the structure of the data effects the sort time. (Explanation Video)
    • Get together with a partner.
    • Revise the timerComparison.py file above so that you:
      • Test each of the three sorts with already sorted data (remove the shuffle)
      • Test each of the three sorts with truly random data (leave the shuffle)
      • Test each of the three sorts with "reverse-order" data (rather than shuffle, reverse the order)
    • Run each set of data several times and with different N values (rather than always 2000, try some other values).
    • Record and discuss your results

     

  2. Revise the algorithms to perform "differently".