Lab 10
comp 125-609, Goldwasser
Tuesday, 9 November 1999

Purpose: How Fast are These Sorting Methods?
In today's lab, our goal is to better understand the time used by four sorting methods which we have seen: Selection Sort, Insertion Sort, Bubble Sort, and Merge Sort.

In the first part of the lab, we will run experiments on these sorting methods for various size arrays, recording the amount of time which each sort uses for a given array.

In the second part of the lab, we will use graphics to display the results.


The time required by these methods depends greatly on the specific code used to implement the high-level ideas. We will provide you with a program executable, which is an enhanced version of the program used in last week's lab. Please begin by down-loading
www.cs.luc.edu/~mhg/comp125/labs/timesort.exe

Although you will not need the full functionality of this program in today's lab, please familiarize yourself with the program now, as this program will also be the basis for the next homework assignment.

When running the program, the following settings may be chosen by the user:

  • The number of items to be sorted
  • The sorting method to be used
  • By default, the initial array is chosen from scratch each time a sort begins. However the user may click on the "Fix Random Seed" box in which case the initial randomization will be based on the value given in the textbox. Fixing a particular random seed allows you to run several different sorting methods on the identically chosen initial values. Also, in debugging during program development, it allows the program to run the code several times on the identical values.
  • Finally, the user must choose between one of three modes
  • "Measure Time Used" - In this mode, the program keeps track of the overall number of seconds which were used to sort the numbers. (Note that animation is turned off in this mode so as not to effect the timing)
  • "Verify Correctness" - In this mode, the program does an additional check at the end to make sure that the array was indeed correctly sorted. For the code which we provide, the sorting is indeed done correctly, however when developing a new method (as in the coming homework), this feature is one useful way to test your programming.
  • "Use Animation" - In this mode, the sorting method is animated using graphics similar to the previous lab. When using graphics, the user gets to choose a Delay factor to slow down the animation speed accordingly, and the user can choose between either color or black and white animation.






  • Now let's gather statistics. Run each of the four sorts on each of the following array sizes: 500, 1000, 2000, 4000, 8000. Record the number of seconds for each experiment in the table below:

    Method 500 1000 2000 4000 8000
    Selection
    Insertion
    Bubble
    Merge


    Now let's use the Visual Basic graphics to give us a quick-and-dirty line graph for displaying our data. Create a picture window and set up the coordinates with the command
    Picture1.Scale (-1000,120)-(10000,-20)
    at run time. Draw the axes by making two lines:
    Picture1.Line (0,0)-(8000,0)
    Picture1.Line (0,0)-(0,120)
    Next label both axes with relevant tick marks. Finally, for each sort, pick a unique color, and graph the five data points for that sort connecting the points with lines in the graph.
    This lab is due before leaving class today. When you have completed both parts of the program, please call me over to your computer to see your graph and data.