Question: Using Java/Eclipse, Write a class called SortComparator which contains a public static void main method. It should do the following: Creates an Integer array of

Using Java/Eclipse, Write a class called SortComparator which contains a public static void main method. It should do the following:

  1. Creates an Integer array of size 128. Call it a.
  2. Fills it up with random numbers between 0 and 100,000. Use

for (int k = 0; k < a.length; k++)

a[k] = (int) (Math.random() * 100000);

to generate your random numbers.

  1. Make 2 more copies of a, call them b and c. Dont just write b = a, etc. Create brand new arrays b and c of the same size as that of a and copy the elements of a into them using for-loops. (Note: as a result, all these arrays a, b, c finally contain exactly the same elements)
  2. Run the Selection sort algorithm on a and note the number of comparisons.
  3. Run the Insertion sort algorithm on b and note the number of comparisons.
  4. Run the Bubble sort algorithm on c and note the number of comparisons.

Repeat 1-6 above for sizes 512, 2048, and 8192. Based on the results you observe from these runs. Complete the following tables with results from your runs. Plot the results in Excel and include the plot in this document.

Number of Comparison Operations

Sorting Method

ArraySize =128

ArraySize = 512

ArraySize = 2048

ArraySize = 8192

Selection Sort

Insertion Sort

Bubble Sort

Which method had the least number of comparisons in each case?

Run the same experiment again (Just run the program again. Results may be different since we are generating whole new sets of random arrays) and note down the results:

Sorting Method

ArraySize =128

ArraySize = 512

ArraySize = 2048

ArraySize = 8192

Selection Sort

Insertion Sort

Bubble Sort

Which method had the least number of comparisons in each case?

SUBMISSION:

Copy and paste all the code and output into this file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!