I'm learning about Big O notation and how it relates to computer science and I understand the sentiment behind Big O, however I'm struggling at understanding how we define a "step".
In the book I'm reading as well as a lot of different articles they use something like below to express an O(N) example since, as N increases we perform more steps linearly:
void printAllElementOfArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
{
printf("%d\n", arr[i]);
}
}
I understand the purpose of the example wherein for the function above "we perform printf N times" and therefore the algorithm is best represented through f(N) <= O(N) (I think that's the mathematical meaning, I get the sentiment of Big O but not fully there yet on the math).
The piece I'm really struggling with though is why we consider "printf" a single step. printf is in itself its own function with its own sequence of steps and so to that end, does that function not need to be elaborated? Is there any defined criteria of when an inner function is elaborated vs when we define it as a unit step?
I read somewhere that usually for nested functions big O is the multiplication of steps for each function O(g(N) x f(N)).
- So to that end, is the implication/assumption here that printf is O(1) and therefore the overall algorithm is O(1*N)?
Any clarifications is really appreciated.