in Algorithms edited by
8,087 views
0 votes
0 votes

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)
in Algorithms edited by
8.1k views

1 Answer

0 votes
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++;

}

}

}

HEre we are using the for loop so that 0(n*(n/3)*(n*n)/3) so that 0(n^4)

Answers is A

edited by
Answer:

Related questions