The selection sort algorithm sorts an array by repeatedly finding the largest (or minimum) element from an
Fantastic news! We've Found the answer you've been seeking!
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 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:
- Your main method accepts a number N from the command argument list. Then use the number N to create an N-element int array.
- Assign random numbers between [0, Integer.MAX_VALUE) to each of the N elements of the array.
- Call selectionSort method to sort the array.
- Display the array elements after each iteration of selection sort.
- Verify the array is sorted after calling your sorting method.
- If you implement all the required methods correctly, the driver program should generate outputs similar to the sample below:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date: