Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What will be the time complexity of the following code?

for(int i = 1;i<=n;i++)
{
    for(int j = i;j<=n;j++)
    {
        //statement -> O(1)
    }
}

The time complexity of the first loop (i) is O(n). I mainly have a problem with the second loop.

Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The overall time (asymptotic analysis) TC would be O(n^2), there will not be exactly n^2 operations!!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading