Assuming that I'm printing a string, as follows:
printf("%s", s);
What can we assume the asymptotic complexity of this function is?
Is it O(n) where n is strlen(s) - it's length? Or is it somehow O(1), constant time. Or something different? I supposed you'd need to know how printf tends to be implemented, however. Any insight is appreciated!
(I should clarify that I'm talking about C rather than C++ but I doubt they're implemented differently)
Edit: added formatting string to printf()
It's complexity is O(m + n), where m is the size of the input and n is the size of the output.
If not passing additional parameters like in your case time complexity is O(2*m) = O(m).
But be aware that your code can fail, because s may contain formatting codes itself and that will produce an undefined/unknown/unpredictable/probably_very_bad result as pointed out by Adriano.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With