Professional Documents
Culture Documents
Time Complexity While Loop
Time Complexity While Loop
While loop
1. i =0 1
while (i<n) n+1
{statement ; n
i++; n
} 3n+2
F(n)= 3n+2
O(n)
OR
For(i=0; i<n;i++) O(n)
{ statement ;
}
A
1
1*2=2
2*2=4
22*2=23 ………..2k
OR
OR
For(i=n; i>1; i=i/2)
4. i=1;
k=1;
while(k<n)
{statement;
K=k+i;
i++;
}
Untill k is less than n this loop will continue otherwise it will terminate.
k>=n
M2+1/2 >=n
M2>=n
M2=n O( 𝑛)
M= 𝑛
{statement;
K=k+I;
5. While (m!=n)
{ If(m>n)
M=m-n;
Else
N=n-m;
}
m/2
Else