0

I want to calculate the order of this function, I calculated but I'm not sure if this right.

This is the 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 ;
    }

And this is my calculus:

For Inner Loop

\1+1+sum_{j=i}^{n-1}(1+1+1)=3n-1

For First loop

\1+1+sum_{i=o}^{n}(3n-1+1)=3n^{2}+2

Finally 3n^{2}+1+2=3n^{2}+3= O(n^{2})

Its right this solution?

Thanks

  • 1
    You already asked essentially the same question once before, and got an answer that explains what the running time of this function is. I'm not sure why you are asking again. Anyway, instead of asking again, please read the answer there, and also please carefully study the material in the the reference question that your original question was closed as a duplicate of. Thank you! – D.W. Aug 04 '16 at 05:28
  • 1
    Also, we discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – D.W. Aug 04 '16 at 05:28
  • This question it to validate the calculus to obtain the order of the function in Big-O notation @D.W. – Jhonny Afonso Aug 04 '16 at 05:30
  • 1
    I'm afraid "check whether my calculations are correct" questions aren't a good fit for this site, per my comment above. – D.W. Aug 04 '16 at 05:31
  • @D.W. Sorry for this, I wanted to check these calculations, I do not have anyone to consult, I thought here could help me, thanks anyway... – Jhonny Afonso Aug 04 '16 at 05:37

0 Answers0