MSD Radix-sort的渐近时间复杂度和空间复杂度

时间:2019-03-25 23:17:38

标签: radix-sort

我已经借助互联网实现了MSD Radix排序。我的作业要求我确定此版本基数排序的渐近时间复杂度和空间复杂度。但是,我对此一无所知。那么有人可以帮我吗?

公共类RadixSort {

public static void radix(String arr[])
{
    msdRadix(arr, 0 , arr.length, 0);
}

public static void msdRadix(String arr[], int low, int high, int d)
{
    if(high <= low+1) 
        return;

    int count[] = new int[256+1];
    String temp[] = new String[256+1];

    for(int i = 0; i < arr.length; i++)
        count[arr[i].charAt(d)+1]++;

    for(int k = 1; k < 256; k++)
        count[k] += count[k-1];

    for(int i = 0; i < arr.length; i++)
        temp[count[arr[i].charAt(d)]++] = arr[i];

    for(int i = 0; i < arr.length; i++)
        arr[i] = temp[i];

    for(int i = 0; i < arr.length; i++)
        msdRadix(arr, 1+count[i], 1+count[i+1], d+1);
}

public static void main(String args[])
{
    String[] arr = {"baa","abb","bbb","aba","bba","aab","aaa"}; // my string array to be sorted by radix sort method.

    radix(arr); // calling radix-sort method

    for(int i = 0; i < arr.length-1; i++)
        System.out.print(arr[i]+", ");
    System.out.println(arr[arr.length-1]);
}

}

0 个答案:

没有答案