CS209 lab1


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l1.html




  1. Study carefully the insertion sort algorithm and code (covered in letures), at https://www.khanacademy.org/computing/computer-science/algorithms/insertion-sort.
  2. Study (and run) the program fcount.py at http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/. The purpose of that short simple program is to show you how you might use a counting variable to determine the number of times a function is called in a program. You should also study the other relevant programs at http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/ such as binINSrec.py, nonBINinsREC.py, etc.
  3. Write a program in PYTHON that carries out insertion sort. In each iteration, for the actual insertion, you must use a function. This can be modelled on functions covered in lectures - e.g. nonBINins(list,item) or nonBINinsREC(list,i,item).
  4. Write a program in PYTHON that carries out binary insertion sort. In each iteration, for the actual insertion, you must use a recursive function.
  5. Test both your programs on a random list of integers of length
    • 50;
    • 500;
    • 5000.
    (for this - you can use random.randrange() as described in the program shops1TIME.py). In each case, determine the number of times your function is called, and report these results when submitting your lab.

© NUI, Galway