CS 104 Lab 6: Compare Sorting Algorithms

Objective:   To gain experience with various Sorting algorithms and their performance differences.
Hypothesis:   Give a hypothesis on the how the sorting algorithms differ in terms of their running time
Solution:   Run experiments on the running time of the sorting algorithms and write a report on how the experiments are conducted, the data collected, how to interpret the data, and how your hypothesis is evaluated based on the data.

 

In this lab, you will write a program to compare the running time of the four sorting algorithms that we have learned: Selection Sort, Insertion Sort, Merge Sort, and Quick Sort. You can modify the sorting program provided in the lecture for this purpose. The amount of work related to actual coding is minimal. The emphasis is on formulating your hypothesis and conducting experiments to evaluate the hypothesis.

The lab has two steps:

  1. Examine the code for the four sorting algorithms and formulate a hypothesis on how they differ in terms of their running time. In your opinion, which sorting algorithm will be the fastest, which will be the second, third, and fourth? Explain the reason for your ranking. Submit the hypothesis on Moodle.
  2. Modify the sorting program provided in the lecture to record the time of the actual sorting. You may use System.currentTimeMillis(); to retrieve the current time stamp in milliseconds (it returns a long data type, which is a long version of int) before and after the sorting and return the difference between them as the running time in milliseconds. Perform each sorting algorithm on inputs of various sizes between 10,000 and 1,000,000 numbers and record the running time in each experiment. For each sorting algorithm and each input size, you should perform several experiments and take the average running time as to minimize the interference from other factors. Create a chart and a graph that show the running time of the four algorithms on various input sizes. An example of such chart and graph is here. Write a report that includes the following and submit it on Moodle.
    • Your original hypothesis.
    • How the experiments are conducted.
    • A chart and a graph showing the data collected.
    • How to interpret the data.
    • How your hypothesis is evaluated based on the data. How scientific uncertainty (randomness in data, variation in measurement, etc) informs the evaluation of hypothesis.

 

Grading Points

Grading Point Allocations

Value

Feature
Conducting the Experiments (6 pts total)
2 pts. appropriately modify the sorting program
2 pts. running enough experiments on various input size
2 pts. collecting the data
 
Writing of the Report (8 pts)
2 pts the report should be thorough and clear
3 pts use appropriate chart and graph to present and interpret date
3 pts explain how scientific uncertainty informs the evaluation of hypothesis
 
Formulate the hypothesis (6 pts)
3 pts quality of the hypothesis
3 pts reasoning of the hypothesis
 
1 bonus pt. other extra features