Question: [JAVA] implement counting sort in java such that it works for negative numbers using the following pseudocode: countingSort(Array A, 1-indexed) { k = largest int
[JAVA] implement counting sort in java such that it works for negative numbers using the following pseudocode:
![[JAVA] implement counting sort in java such that it works for negative](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66dbc4c1ab3a0_78566dbc4c14ffba.jpg)
countingSort(Array A, 1-indexed) { k = largest int in A C = Array of k+1 zeros, 0-indexed for x in A C[x] = C[x] + 1 // C[i] = num elements equal to i for 1 to k C[i] = C[i] + C[i-1] // cumulative array B = Output Array, same length as A for j = A. length -> 1 B[C[A[j]]] = A[j] C[A[j]] = C[A[j]]-1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
