Hi everyone
I want to calculate the complexity of this algorithm:

 int function (int n, int m)
    int result=0;
    for(i=0;i<n;i++)
       {
       for (j=0;j<m;j++)
         result=result+i*j;
       };
    end

so I proceeded as the following:

as the programme is composed of two loops I started by calculating the number of operations of the second one to find that it is 3m+1;
this number of operations will be repeated n times as the first loop repeats witch is n(3m+1) +2n as total of operations ...
Does that means that the complexity of this problem is i order of O(mn)?? or is it jut that my calculations went wrong?
thanks for you help

Simple. Outer loop == n iterations. Inner loop == m iterations. Total iterations? n * m. It really is not a complexity problem since the problem is linear.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.