Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 MySort(A, n) //A is the array, n is array length
- 2 uniqueDigitsNum <- 5log_n(n) + 1=6
- 3 init countArray // the array of length uniqueDigitsNum
- 4 for i <- 0 to n //O(n)
- 5 //B is a helper array which will store how many digits are in a given number
- 6 countDigits(A[i], B[i])
- 7 countArray[B[i]]++ //update the count of how many times we see x digits in CountArray
- 8 // init a 2d array which will contain uniqueDigitsNum subarrays
- 9 init subArrays of length uniqueDigitsNum
- 10 for k <- 0 to uniqueDigitsNum //O(6)
- 11 init subArrays[k] of length countArray[k]
- 12 for k <- 0 to uniqueDigitsNum //O(6n)
- 13 Radix-Sort(subArrays[k]) //O(countArray[k])
- 14 //we'll need 'j' to know at which index to start copying the next subarray in the big output array
- 15 j <- 0
- 16 for k <- 0 to uniqueDigitsNum //O(n)
- 17 for j to countArray[j] //O(countArray[j])
- 18 outputArray[j] <- subArrays[k][j]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement