What does O(log n) mean exactly?

后端 未结 30 2419
执念已碎
执念已碎 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 01:47

    These 2 cases will take O(log n) time

    case 1: f(int n) {
          int i;
          for (i = 1; i < n; i=i*2)
            printf("%d", i);
        }
    
    
     case 2  : f(int n) {
          int i;
          for (i = n; i>=1 ; i=i/2)
            printf("%d", i);
        }
    

提交回复
热议问题