• retagged by
2,611 views

2 Answers

Best answer
4 4 votes

Value of i always remains 0 hence it gets trapped in outer loop indefinitely, irrespective of the values of n.

That means, it doesn't depend on the input.

Therefore, it's time complexity is O(1).

• selected by
0 0 votes
if i=0 is replaced by 1 then inner loop will execute 1,2,4,8,16,32 ...log2n times so total no of times =2^logn-1/2-1=>O(2^log n)=>0(n )
• edited by
Position:
Show:

Related questions

1 1 vote
2 2 answers
1.3k
1.3k views
Apeksha asked Aug 6, 2016
1,297 views
for(i=1;i<=n;i++) for(j=1;j<=i;j++) for(k=1;k<=j;k++) for(l=1;l<=k;l++) printf("gate");
0 0 votes
2 2 answers
1.2k
1.2k views
kalpashri asked May 12, 2015
1,193 views
for(i=1;i<=n;i=i*2);for(j=1;j<=i;j=j+1);{}
2 2 votes
1 1 answer
1.5k
1.5k views
Narasimhan asked Nov 7, 2017
1,457 views
// func() is any constant root functionfor (int i = n; i 0; i = func(i)){ // some O(1) expressions or statements}"In this case, i takes values n, n1/k, (n1/k)1/k = n1/...
1 1 vote
0 0 answers
3.0k
3.0k views
sripo asked Nov 6, 2018
2,984 views
What is the time complexity for infinite loopsQuestion 1 what is T(n) for this caseWhile(1){a=a+b;} Question 2 for this caseif(1){for i to na=a+b}else{for i to nfor j to...