Advertisement
Guest User

Untitled

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