0

I have this function

int fct (int Y){
        int y = 0 ;
        for ( int i =0; i<Y;++ i ){
            for ( int j=i ; j >=0;--j ){
                y++;
                }
            }
            return y ;
    }

I want to know the order of this function, I know that the first for loop its O(n), but I confused to the second for lood, I'm not sure if is O(n).

I think the order of function its O(n^2)

Any help?

Raphael
  • 72,336
  • 29
  • 179
  • 389
Jhonny
  • 1
  • 1
    you are correct it is $O(n^2)$. – advocateofnone Aug 03 '16 at 14:58
  • This is answered at length at our reference question which I'm going to close this as a duplicate of. There are also many examples via [tag:algorithm-analysis+loops]. – Raphael Aug 04 '16 at 01:18
  • 1
  • What is n? There is none in your code. 2) Have you tried any structured approach? 3) Which "complexity"? That's not a very meaningful notion. Do you mean "$\Theta$-class of its running-time cost function"?
  • – Raphael Aug 04 '16 at 01:18