0

enter image description here

Can anyone tell me answer for this algorithm?

I Think the answer is O(nlogn) but i’m not confident with my answer

  • 3
    I think it's still O(n^2), like optimised bubble sort – Lewis Kelsey Jun 21 '20 at 16:09
  • Please post code as text. – Evg Jun 21 '20 at 16:40
  • 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) – Mark Rotteveel Jun 21 '20 at 16:40
  • Imagine the loops printing `*` in a triangle shape, one more `*` in each line. The area of the triangle (number of `*`) corresponds to the number of iterations of the inner loop, and thus the complexity. And the area of a triangle is (w*h)/2, i.e. 0.5n², i.e. O(n²). – tobias_k Jun 21 '20 at 16:41

1 Answers1

2

it will be n^2. as the loop give complexity of n. and loop are nested so its n*n=n^2.

AFzal Khan
  • 81
  • 6