java - Complexity of LSD string sort (cfr. Algorithms by Sedgewick & Wayne) -


in algorithms sedgewick & wayne (4th edition), state lsd string sort uses 7wn + 3r array accesses , space proportional n+r sort n items keys w-character strings taken r-character alphabet.

they prove saying: "the method w passes of key-indexed counting, except aux[] arrays initialized once.the total immediate code , proposition a."

however, 2 pages back, state key-indexed counting uses 11n + 4r + 1 array accesses stably sort n items between 0 , r-1.

how possible? shouldn't lsd n+w(4r + 10n) ?

just clear, i'm not looking big-o notation.

thanks in advance!

code key-indexed counting sort (according algorithms):

int n = a.length; int[] count = new int[r+1]; (int = 0; < n; i++)    count[a[i]+1]++; (int r = 0; r < r; r++)    count[r+1] += count[r]; (int = 0; < n; i++)    aux[count[a[i]]++] = a[i]; (int = 0; < n; i++)    a[i] = aux[i]; 

code lsd string sort

int n = a.length; int r = 256; string[] aux = new string[n];     (int d = w-1; d >= 0; d--)      {          int[] count = new int[r+1];         (int = 0; < n; i++)             count[a[i].charat(d) + 1]++;          (int r = 0; r < r; r++)             count[r+1] += count[r];          (int = 0; < n; i++)             aux[count[a[i].charat(d)]++] = a[i];          (int = 0; < n; i++)             a[i] = aux[i];         }     } } 


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -