The Gateway to Computer Science Excellence
0 votes
285 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)
in Algorithms by (117 points)
edited by | 285 views

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

}

}

}

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

Answers is A

by Active (1.8k points)
edited by
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,291 answers
198,209 comments
104,890 users