What is the time complexity of the following function foo()
foo()
void foo() { int i, j; for(i = 1; i <= n ; i++) for(j = i; j <= log(i); j++) printf(“gate”); }
nlogn
.
O(n)
yes, in the given code, it should be O(n).
But there is a typo in j = i.
j = i.
If instead j = 1, then answer would have been nlogn
j = 1
64.3k questions
77.9k answers
244k comments
80.0k users