Write a JAVA Program: Compare the performance of bubble sort and selection sort
ID: 3705748 • Letter: W
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. 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.
Explanation / Answer
Hi Dear,
Please find my basic implementation.
Output:
Bubble Sort:
Comparisons : 4950
Swaps : 2337
Selection Sort:
Comparisons : 4950
Swaps : 99
Process finished with exit code 0
Please DONT forgot to rate my answer. We are working hard for you Guys!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.