Lab 11: Sorting (Selection Sort)
Due Date and Submission Requirements
- Due Date: Thursday, November 14th at 11:59 p.m.
- Partner Information: This is an individual assignment. You are allowed to collaborate with other students, but each student must submit their individual, independent solution.
- Submission Instructions: Submit your Lab11Demo.java file to the appropriate D2L dropbox.
The goal of this lab is:
- Implement Selection Sort in Java
Directions
Using Lab11Demo.java as a starting point, you will fill in the body of the selection_sort method so that it sorts a given array using the Selection Sort algorithm. This method has one argument (an unsorted array), and returns a sorted array.
Selection sort is a simple and (somewhat) efficient sorting algorithm that works by repeatedly selecting the smallest element (or largest if you are sorting from greatest to least) from the unsorted portion of the list and swaps it with the first element of the unsorted portion. This process is repeated for the remaining unsorted portion of the list until the entire list is sorted.
If selection sort still does not make sense, you should watch this video.
You are NOT allowed to modify the Lab11Demo class other than the code inside of the selection_sort method.
Starting Code
Output
When you run your program, your output should look something like this: sample output. Because random numbers are used, your output will be different, but your array should be sorted after calling the selection_sort method. Your time taken in ms will also be slightly different due to computer hardware
Grading (10 points)
- 8 points- the algorithm for selection sort is correct
- 2 points- nothing else in the demo class was modified