edited by
958 views
2 votes
2 votes

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...

edited by

1 Answer

Related questions

0 votes
0 votes
1 answer
1
saptarshiDey asked Jan 3, 2019
8,080 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++; } } }Option...
1 votes
1 votes
2 answers
2
APOORV PANSE asked Jun 1, 2016
2,991 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=...
2 votes
2 votes
3 answers
3
admin asked Oct 8, 2015
1,208 views
int Test(int n) { if (n<=0) return 0; else { int i = random(n-1); return Test(i) + Test(n-1-i); } }Suppose the function $\text{random}()$ takes constant time, then what ...