此排序问题的时间复杂度是多少?

问题描述 投票:0回答:1

该问题的数组大小为n [1-100]。创建一个排序算法并讨论它的时间,空间和最佳性。我对渐近分析没有很好的理解,也不确定如何回答。

算法:

void sort(int a[], int n) {
    int temp[100] = {0};
    for(int i=0; i<n; i++)
        temp[a[i]-1]++;
    int c = 0;
    for(int i=0; i<100; i++)
        for(int j=0; j<temp[i]; j++) {
            a[c] = i+1;
            c++;
        }

  }
sorting time-complexity complexity-theory space-complexity
1个回答
0
投票

O(n),请参考Count Sort

© www.soinside.com 2019 - 2024. All rights reserved.