# Time Complexity of Code snippet

0 votes
734 views

What will be the worst case time complexity for the following code segment?

int count=0,N;
for(i=0;i<N*2;i++){
for(j=0;j<i/3;i++){
for(k=0;k<j*j;k++){
count++;
}
}
}

Options:

1. O(N^4)
2. O(N^3)
3. O(N^2)
4. O(N)

edited

## 1 Answer

0 votes

Best answer

int count=0,N; --------(1)

for(i=0;i<N*2;i++){     ----->0(n)

for(j=0;j<i/3;i++){   0(n/3)

for(k=0;k<j*j;k++){    0((n*n)/3)

count++;

}

}

}

Answers is A

edited by

## Related questions

1 vote
1 answer
1
411 views
for i <--- 1 to n for j <---- 1 to n/2 X = X + 1 (i and j both are incrementing by 1) Outer runs for n times and inner for n/2 So will it be n(n/2) => O(n^2) times...
1 vote
1 answer
2
766 views
What is time complexity of following code : int count = 0; for (int i = N; i > 0; i /= 2) { for (int j = 0; j < i; j++) { count += 1; } } Please give ans with explanation ? Thankyou
0 votes
2 answers
3
789 views
Consider the following c fragment : void DAA(n) { int i,j,k,x=0; for (i=1 ; i <=n ; i++) for (j=1 ; j <= i * i ; j++) { if ( j mod i == 0 ) for ( k = 1 ; k <= j ; k++) x=x+10; } } Find the time complexity of above code in terms of input size n.
0 votes
1 answer
4
179 views