Answered step by step
Verified Expert Solution
Question
1 Approved Answer
algorithm: Counting - SORT ( A , n , k ) let B [ 1 : n ] and C [ 0 : k ]
algorithm:
CountingSORT
let : and : be new arrays
for to
for to
now contains the number of elements equal to
for to
now contains the number of elements less than or equal to
Copy to starting from the end of
for downto
to handle duplicate values
return
Your sort takes the array A input and value as arguments. In Java, determine
by asking the array for its length.
Create public static method sort which implements a counting sort for nonnegative integers. It takes two parameters:
an array of integers int input containing the values to be sorted as the first argument do not change the contents of this array
an int maximumValue which is the largest value the input array may contain as the second argument
sort returns a new array of integers containing the sorted output.
Note: you will not be given any values outside the specified range do not check for negative or 'too large' values.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started