Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TFW @ 86% 12:48 PM Lab3.docx Run the program a few times to verify that the sorting methods Lab 3 are correct. Task 3: Modify

image text in transcribed
image text in transcribed
TFW @ 86% 12:48 PM Lab3.docx Run the program a few times to verify that the sorting methods Lab 3 are correct. Task 3: Modify the main method so that it computes the amount of time each sorting algorithm takes to sort an array of integers. You will do this by calling System.currentTimeMillis0 to get the current time in milliseconds (store the result in a long variable, not an int) immediately before you call Selection Sort and again immediately after you call Selection Sort. Use the times to compute how long Selection Sort took and print the result. Do the same for Bubble Sort. Before you test your program, you must increase the array size. An array of 30 integers will be sorted so fast, the time will probably be reported as 0. Instead, use an array size of 1000 NOTE: Do not print the arrays for sizes greater than 30 Task 4: You will now conduct more tests and record the resulting times. Use the following array sizes and record the times for Selection Sort and Bubble Sort in each case. Test 1: 1000 Test 2: 10,000 Test 3: 50,000 Test 4: 75,000 Test 5: 100,000 Test 6: 150,000 Test 7: 200,000 Test 8: 1,000,000 (just kidding!) Task 5: Modify the Selection Sort and Bubble Sort methods so that each one counts the number of swaps performed. Each method must print the final count when done. (You will probably want to store the count in a long variable instead of arn int..especially for Bubble Sort.) Repeat the above Tests 1-5 and record the resulting number of swaps for Selection Sort and Bubble Sort. Dashboard Calendar To Do Notifications Inbox TFW 12:48 PM @ 86% Lab 3 Lab3.docx Test 1: 1000 Test 2: 10,000 Test 3: 50,000 Test 4: 75,000 Test 5: 100,000 Test 6: 150,000 Test 7: 200,000 Test 8: 1,000,000 just kidding!) Task 5: Modify the Selection Sort and Bubble Sort methods so that each one counts the number of swaps performed. Each method must print the final count when done. (You will probably want to store the count in a long variable instead of an int...especially for Bubble Sort.) Repeat the above Tests 1-5 and record the resulting number of swaps for Selection Sort and Bubble Sort. Task 6: Finally, you will implement the Heap Sort algorithm (you don't need to know how it works today, just follow these directions...you'll learn about the Heap later). In this method, create a new PriorityQueue Integer> object (import ava.util.PriorityQueue). You use a PriorityQueue the same way that you use an ArrayList. Write a loop to add all of the integens from the given array to the PriorityQueue. Then, write g separate loop to remove all of the integers from the PriorityQueue and put them back in the array, left-to-right. Just call the PriorityQueue's remove0 method (no parameter) to remove each integer. Because of the magic of the PriorityQueue, the integers will automatically be removed in ascending order. You'll learn how later. Run a test of Heap Sort on an array of 30 integers. Print the random and sorted arrays to verify that Heap Sort actually sorts the array. Repeat the above Tests 1-8 just for Heap Sort and record the times. Submit your L oopSort.java file as well as all test results. Dashboard Calendar To Do Notifications Inbox

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

Identify fraud risks associated with debt obligations.

Answered: 1 week ago