Radix sort: LSD versus MSD versions

后端 未结 3 1108
失恋的感觉
失恋的感觉 2021-02-04 02:36

The book \"Introduction to Algorithms\" mentions about the LSD (Least Significant Digit) version of radix sort. However , as others have pointed out here in stackoverflow, a MSD

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 03:01

    As read in the book Algorithms, LSD and MSD are both string array sorting algorithms, based on the so-called key indexed counting rather than on comparisons. Therefore, LSD and MSD have a different running time versus traditional quick sort or merge sort.

    As Dzhabarov mentioned, the biggest difference between LSD and MSD is that MSD considers the most significant digit or character first, which by nature sorts strings without iterating through all of the digits in the strings. This is an advantage. However, a recursive implementation of MSD uses more space than LSD.

    The table below illustrates parts of the difference among quick sort, LSD and MSD.

    algorithm    running time              extra space
    quicksort    N(lgN)^2                  1
    LSD          NW                        N
    MSD          between N and NW          N + WR
    

    where N is the length of array, and W is the length of string, and R is size of radix.

    PS: as mentioned in the book, the Java system sort uses a general sorting algorithm with fast string comparison and not LSD or MSD.

提交回复
热议问题