Question: Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles.

Write a JAVA Program:

Compare the performance of bubble sort and selection sort over several arrays.

- Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort.

- In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately)

- Each time an array is sorted, print out the name of the algorithm used (selection or bubble), the number of comparisons, and the number of swaps. You may print these out from within the sort function; you do not need to figure out how to pass these values back to main()

- In main(), create several arrays and run the sort algorithms for each of them. Include one array that is already sorted, one that is sorted in descending order, one that has no obvious order, and one or two other ones that use whatever patterns you think are interesting.

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!