Question: This contains the implementation of the Counting Sort algorithm where the given list of numbers is sorted in ascending order. Provide the needed changes in

 This contains the implementation of the Counting Sort algorithm where the

This contains the implementation of the Counting Sort algorithm where the given list of numbers is sorted in ascending order.

Provide the needed changes in the provided pseudo code to sort the given list of numbers in descending order instead.

COUNTING-SORT(A, B, k) 1 let C[0.. k] be a new array 2 for i = 0 to k 3 C[i] = 0 4 for j = 1 to A.length 5 CA[j]] = C[A[j]] + 1 6 // C[i]= number of // elements equal to i. 7 for i = 1 to k 8 C[i] = C[i] + C[i 1] 9 // C[i]= number of // elements less than or equal to i. 10 for j = A.length downto 1 11 B[C[A[j]]] = A[j] 12 C[A[j]] = C[A[j]] 1

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!