retagged by
517 views
0 votes
0 votes
1.  for ( i = 1 ; i <= n ; i++)

{

     for ( j= 1 ; j <= i; j++)

{

     for ( k = 1 ; k <= j ; k++)

        cout<<"a";

}

}

     

Here , complexity = O(n³)

 

2.

for ( i = 1 ; i <= n ; i=i*2)

{

     for ( j = 1 ; j <= i ; j++)

        cout<<"a";

}

Here , complexity = O(n) . But I am getting O(2^n)

 

(A gp was formed , first term = 1 = 2^0 , last term was 2^n so sum is 2^(n+1) which gives complexity as 2^n)
retagged by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
2
0 votes
0 votes
1 answer
3
NeelParekh asked Jul 27, 2023
275 views
If an array is split in the form of increasing and decreasing order then what is TC to find minimum element in the array?
2 votes
2 votes
1 answer
4
h4kr asked Dec 30, 2022
462 views
What is the correct time complexity in $\theta()$ ?