Time Complexity Analysis of a function (Big-O)

Viewed 49

Can I ask somebody to help me start with this algorithm's time complexity? I'm specifically trying to figure out how can get the Big O.

Few things I think I know is that the while is probably O(n) and the 'for' is O(n) because of the T.length which gives it not to be a constant. But I'm not sure if this means that the whole algorithm probably will be O(n^2) or just simply O(n) or am I in the complete wrong path?

The function's description says that it supposed to do 'SquareRootByItems'.

int function(int T[]){
for (int i := 0; i < T.length; i++){
    int j := 1;
    while(j * j <= T[i]) j++;
    T[i] := j;
  }
  return 0;
}

Thanks everybody for their help.

0 Answers
Related