1

Can someone give me a good explanation for Big-O problem

int fun(int n){
   for (int i = 2; i<=n; i++)
     for(int j= 2; j<2n: j+=i
       System.out.println("Ok");
}
  • The system.out should print the value of `i` and `j` so you can see what the loop is doing. – user3386109 Jun 20 '20 at 06:02
  • If you search for "Big O" and "nested loops" you will find a lot of similar questions and answers that could help you understand your particular problem. – hlg Jun 20 '20 at 06:25
  • Just print the values of i and j in each iteration, you will get your explaination. – Nitin Singhal Jun 20 '20 at 06:58
  • Does this answer your question? [Big O, how do you calculate/approximate it?](https://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it) – Paul Hankin Jun 20 '20 at 07:12
  • 3
    I don't think the question shows enough effort put into solving it, but I disagree with the other commentary that this is a particularly simple question. Try writing a mathematical expression for how many times "Ok" is printed for a particular value of i, and then sum it up. You should get an expression that involves harmonic numbers. If you get stuck when you actually try to solve it, try to formulate a more specific question with the actual problem that you encountered. – Paul Hankin Jun 20 '20 at 07:21

0 Answers0