Question: Searching and sorting Java program instructions. In a Java application: Instantiate two ArrayLists of Integers. Fill your two ArrayLists with 50 randomly generated integers. Use

Searching and sorting Java program instructions.

In a Java application:

Instantiate two ArrayLists of Integers.

Fill your two ArrayLists with 50 randomly generated integers. Use the entire possible range of random integers.

hint: call nextInt() with no argument

hint: to start, you might want to use just 5 integers to get things working. Modify to 50 once everything is working.

Write a different sorting algorithm to sort each ArrayList. You are free to use any of the algorithms we studied in this module, or any other sorting algorithm you like, but you must implement the logic. Do not just call a pre-existing sort() method or similar; you must implement your algorithms in your programs. It's fine to utilize existing resources to help you write these algorithms; be sure to cite your sources!!

hint: to start, print the contents of the ArrayLists before and after sorting to make sure everything is working. Once you are confident that your sorting algorithms are working, you will probably want to disable the printing logic before you start getting into larger ArrayLists...

Run your program and determine how long each of your sorting algorithms takes to sort your ArrayLists. Please use nanosecond scale.

hint: long startTime = System.nanoTime();

hint: we want to track algorithm performance... so where / when should we be recording the starting and ending times?

In a table like this one, note how long in nanoseconds each algorithm takes to sort your ArrayLists:

number of elements bubble sort selection sort
50 156156 123123
500
5000
50000

(note: values are illustrative only!)

Modify your program to fill your ArrayLists with 500 randomly generated integers, then 5000, then 50000. Run your program each time you modify the number of elements you're adding to your ArrayLists, and add the appropriate performance data to your table each time.

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!