Home > Net >  What is the best and worst case for the following snippet?
What is the best and worst case for the following snippet?

Time:04-30

for (int index = 1; index < n; index *= 2) {
    int counter = 0;
    while (counter < n) {
       counter  ;
    }
}

Determine its best and worst case runtime in the Big-Theta notation as a function of n.

I think the worst case is n*log(n), but I am not sure about the best case.

CodePudding user response:

The time complexity is indeed O(

  • Related