I'm a beginner in data structure and algorithms. I have come across this problem in a book (Data Structures And Algorithms Made Easy In Java) and the complexity is given as O(√n) in the book. To my understanding, it looks the function grows more than O(√n) but less than O(n) with the input.
public void function (int n) {
int i=1, s=1;
// s is increasing not at rate 1 but i
while( s <= n) {
i++;
s= s+i;
System.out.println(“*");
}
}
Can you please explain what is the correct time complexity of this function?