Rational Rose简明实用教程

转载


https://blog.csdn.net/gz153016/article/details/49641847

求下列算法的时间复杂度

void aFunc(int n) {
    for (int i = 2; i < n; i++) {
        i *= 2;
        printf("%i\n", i);
    }
}

假设 t 为循环体的执行次数,则执行 t 次需要满足条件  2^t<n,则执行次数 t = log(2)(n),所以时间复杂度为 O(logn)

17:16:33

2018-11-24

猜你喜欢

转载自www.cnblogs.com/chiweiming/p/10012761.html
今日推荐