Question: The selection sort algorithm sorts an array by repeatedly finding the largest (or minimum) element from an unsorted part and putting it at the end

The selection sort algorithm sorts an array by repeatedly finding the largest (or minimum) element from an unsorted part and putting it at the end of the unsorted part. 

Your Tasks:

 create a program named SelectionSortPA.java  and implement selection sorting algorithm as specified below: 

Public static void selectionSort(int[] arr)    

// Refer to the program for MergeSort in Module 3B Guided Assignment: Problem 2.

Once completed, test your sorting algorithm as follows:

  1. Your main method accepts a number N from the command argument list. Then use the number N to create an N-element int array.

  2. Assign random numbers between [0, Integer.MAX_VALUE) to each of the N elements of the array.

  3. Call selectionSort method to sort the array.

  4. Display the array elements after each iteration of selection sort.

  5. Verify the array is sorted after calling your sorting method.

  6. If you implement all the required methods correctly, the driver program should generate outputs similar to the sample below:>java SelectionSort 8 46 45 25 38 37 10 7 24 Is

>java SelectionSort 8 46 45 25 38 37 10 7 24 Is the array sorted? false 46 45 25 38 37 10 7 24 7 45 25 38 37 10 46 24 7 10 25 38 37 45 46 24 7 10 24 38 37 45 46 25 7 10 24 25 37 45 46 38 7 10 24 25 37 45 46 38 7 10 24 25 37 38 46 45 The array is sorted after calling Selection Sort 7 10 24 25 37 38 45 46

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Below is a Java program named SelectionSortPAjava that implements the selection sort algorithm as sp... View full answer

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 Programming Questions!