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)...
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)?
1 Answer
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.