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

Is an algorithm whose time complexity increases with input but with a limit considered O(n)?

if a function’s statements execution increases with input but with a limit, would it be considered O(n) or O(1)?

for example:

void func(int n)
    {
        if (n > 1000)
        {
            for (int i = 0; i < 1000; i++)
            {
                //do thing
            }
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                //do same thing
            }
        }
    }

is this function O(n) or O(1)?

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 :

It is O(1), not O(n).

Big-O analysis is asymptotic: it intentionally ignores an arbitrarily large initial section of the performance function, in order to accurately describe the large-scale behavior.

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