Time complexity for the following algorithm with loops

25 Views Asked by At

I have the following algorithm and I want to find the time complexity:

for(int i=1; i<=n; i++)
{
    for(int j=1; j<=m; j++)
    {
        for(int k=1; k<=o; k++)
        {
            for(int l=1; l<=p; l++)
            {
                //some stuff
            }
        }
    }
}

Is this $O(nmop)$ or $O(n^4)$ and if it is $O(nmop)$ does it mean that it is better than $O(n^4)$

1

There are 1 best solutions below

1
On BEST ANSWER

It is $O(nmop)$, not $O(nmkl)$ (although $o$ is reserved for something else), and it is not better than $O(n^4)$ since letting $n=m=o=p$ gets you there.