What is the running time complexity of following fucntion.
public void funtion(int n){
int i=1,s=1;
while(s<=n){
i++;
s=s+i;
System.out.println("*");
}
}
What is the running time complexity of following fucntion.
public void funtion(int n){
int i=1,s=1;
while(s<=n){
i++;
s=s+i;
System.out.println("*");
}
}
At step k, S=sum (i for i in 1,K)=K(K+1)/2
So you will make K loops with k such that k(k+1)/2=n
k**2+K-2n=0 the positive root is K = (-1+sqrt(1+8n))/2 = sqrt(1/4+2n)-1/2