CSCE 146

Lab 13

In this lab we’ll compare the efficiency of various sorting algorithms with respect to the number of comparisons made to sort a list of numbers.

1.      Write a method to generate an array of  ‘n’ random integers. The signature of the method is :

public int[] randomNumbers(int n)

{

         //method implementation

}

 

The random numbers generated should have a Gaussian distribution with a mean of 525 and standard deviation of 100. Generate these numbers as you did in Lab-08, using the nextGaussian() method of the Random class and the formula

 

y = m + s * x

2.      Download the following classes that implement various sorting algorithms.

Selection Sort

Insertion Sort

Shell Sort

Quick Sort

3.      Modify each of the above sorting routines so that they return a count of the number of comparisons (C) made to sort an array of integers.

4.      Invoke each of the sorting routines for an array of random integers of a given size and record the number of comparisons involved in the sort. Now vary the size of the array  and record the number of comparisons in the table below :

Size of Array

CSelection Sort

CInsertion Sort

CShell Sort

CQuick Sort

N = 100

 

 

 

 

N = 1000

 

 

 

 

N = 10,000

 

 

 

 

 

        Enjoy!!