What does O(log n) mean exactly?

后端 未结 30 2914
执念已碎
执念已碎 2020-11-22 01:19

I am learning about Big O Notation running times and amortized times. I understand the notion of O(n) linear time, meaning that the size of the input affects the g

30条回答
  •  执笔经年
    2020-11-22 02:04

    Algorithms in the Divide and Conquer paradigm are of complexity O(logn). One example here, calculate your own power function,

    int power(int x, unsigned int y)
    {
        int temp;
        if( y == 0)
            return 1;
        temp = power(x, y/2);
        if (y%2 == 0)
            return temp*temp;
        else
            return x*temp*temp;
    }
    

    from http://www.geeksforgeeks.org/write-a-c-program-to-calculate-powxn/

提交回复
热议问题