Professional Documents
Culture Documents
int i, j;
printf("…");
Θ(n log n)
function(int n)
{
if (n==1)
return;
printf("*");
break;
Time Complexity of the above function O(n). Even though the inner loop is bounded by n,
but due to break statement it is executing only once.
void function(int n)
int count = 0;
count++;
}
Time Complexity of the above function O(n log2n)
void function(int n)
int count = 0;
count++;
void function(int n)
int i = 1, s =1;
while (s <= n)
i++;
s += i;
printf("*");
void function(int n)
int count = 0;
if (j%i == 0)
int count = 0;
// executes n times
if (j%i == 0)
printf("*");
O(n2)
for (int i = 1; i <=n; i *= c) {
O(Logn)
Recursive Fibonacci is exponential (O(2N)) , not good!