Question: In bubbleSort.java (Listing 3.1 in your text) rewrite main() so it creates a large array and fillsthat array with data. You can use the following

In bubbleSort.java (Listing 3.1 in your text) rewrite main() so it creates a large array and fillsthat array with data. You can use the following code to generate random numbers:

for(int j=0; j { // random numbers long n = (long)( java.lang.Math.random()*(maxSize-1) ); arr.insert(n); }

BUBBLESORT

https://dmacc.blackboard.com/bbcswebdav/pid-2721734-dt-content-rid-29565697_1/courses/201801_CIS152_12928/bubbleSort.java

Insert 10,000 items. Display the data before and after the sort. Youll see that scrolling the display takes a long time. Take Screenshot Number 1 of the your changed code.

Next comment out the calls to display(). Add timing if necessary to see how long the sort itself takes. Need help with timing? See https://stackoverflow.com/questions/20211648/how-to-measure-time-taken-by-java-code. The time will vary on different machines. Take Screenshot Number 2 of your results.

Sorting 100,000 numbers will probably take less than 30 seconds. Now, select an array size that takes about this long and time it. Take Screenshot Number 3 of these results.

SELECTION SORT

https://dmacc.blackboard.com/bbcswebdav/pid-2721734-dt-content-rid-29565699_1/courses/201801_CIS152_12928/selectSort.java

Now, perform the same experiment on the Selection Sort. selectSort.java (Listing 3.2) using the same timing method you used. This will be Screenshot Number 4, Screenshot Number 5, Screenshot Number 6.

INSERTION SORT

https://dmacc.blackboard.com/bbcswebdav/pid-2721734-dt-content-rid-29565698_1/courses/201801_CIS152_12928/insertionSort.java

Now, perform the same experiment on the Selection Sort. insertionSort.java (Listing 3.3) using the same timing method you used. This will be Screenshot Number 7, Screenshot Number 8, Screenshot Number 9.

I. BUBBLE SORT

Paragraph and Screenshot Number 1

Paragraph and Screenshot Number 2

Paragraph and Screenshot Number 3

II. SELECTION SORT

Paragraph and Screenshot Number 4

Paragraph and Screenshot Number 5

Paragraph and Screenshot Number 6

III. INSERTION SORT

Paragraph and Screenshot Number 7

Paragraph and Screenshot Number 8

Paragraph and Screenshot Number 9

IV. SUMMARY AND CONCLUSION

Paragraph comparing Bubble, Insertion and Selection Sort algorithms.

Paragraph comparing Bubble, Insertion and Selection Sort timing.

Paragraph discussing the necessity to look at 10,000 and even larger arrays when testing timing.

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!