Time complexity

whats time complexity of program if
there are two different loop with same range n has been nested inside of loop that has range of m.

1 Like

@abhaypandey114
The time complexity should be O(m*n) I believe for something like the structure below.

You should also check out the following article.

Time-Complexity

for(i=0;i<m;i++)
{
    for(j=0;j<n;j++)
    {
    }

    for(k=0;k<n;k++)
    {
    }

}

ohh!!! is that mean, both n range loop get added up , which may result as O(2n) where 2 is constant , which get neglected and O(n) left out.
which make O(m) * O(n) ===> O(m * n)
??
and thanks for response!!

@abhaypandey114
Yes, that is correct.

2 Likes