Search for question
Question

Write a complete program in Java which will generate increasingly larger sequences of random unsigned integers, sorts each sequence into ascending order (counting the number of comparison basic operations necessary to

complete the sort), and prints the number of comparisons required for each randomized sequence sorted. Carefully follow the design and instructions below and on the next page. One of the sorting algorithms employed in this assignment (see next page) is the CombSort - a generalization of a bubble sort that permits comparison of non-adjacent items, retaining the simplicity of a bubble sort but with a dramatic increase in speed (https://www.youtube.com/watch?v=ob49RukGnAw). To test this premise, repeat this exercise with the following algorithms to allow for empirical comparison with CombSort: Selection Sort -- an O(n²) algorithm Bubble Sort (enhanced as was discussed) -- an O(n²) algorithm Since your program will be comparing the efficiency of three sorting algorithms, you should include all three algorithms into a single program (with each algorithm being executed for randomized arrays of size 10, 100, 1000, and 10000). Be sure to incorporate the count operation immediately prior to the comparison basic operation in each algorithm so that both are always executed in an unimpeded sequence. It is highly advisable that during testing you print selectively sized results from each algorithm to ensure they are sorting the randomized data as expected. For each algorithm and array size, output should appear like the following for each program run (or algorithm invocation): SORTING ALGORITHM: (Combsort/Bubble Sort/Selection Sort) Number of values in array: 10 Number of comparisons required: xx Number of values in array: 100 Number of comparisons required: xxxx Number of values in array: 1000 Number of comparisons required: xxxxxx/n{ global variables: IntArray, an array of no more than 10000 integers; Index, an integer; Comparisons, a long integer } for Index 10, 100, 1000, 10000 end for end CombSort Comparisons 0 Generate ( IntArray, Index) Sort IntArray, Index) Output ( Index, Comparisons) Generate ( ValueArray ( an array of integers, passed by reference }; Count an integer, passed by value } ) {local variable: Temp, an integer } for Temp 1,2, Count ValueArray [Temp] a random integer between 0 and maximum integer end for end Generate Output ( Index { an integer, passed by value }; Count { a long integer, passed by value } ) print("Number of values in array:", Index) print("Number of comparisons required: ", Count) print a blank line. end Output Swap ( Valuel, Value2 { integers, passed by reference }) {local variable: Temp, an integer } Temp Value1 Value1 Value2 Value2 Temp end Swap Sort ( Value { an array of integers, passed by reference }; Tally an integer, passed by value }) {local variables: I, J, Gap: integers; Swapped. a boolean

Fig: 1

Fig: 2