What is the time complexity of writing a string for the console?

My colleague and I were discussing the time complexity of writing a string for the console, and without being able to find an answer online, I thought I would ask here:

Let's say I have a string of length n. Is writing this line to the console always an O (n) operation? I assumed it should be at least O (n), but without being intimately familiar with how the console works, I can't say for sure.


source to share

1 answer

In theory, yes, it's O (N). In fact, there is often enough overhead of initially accessing the console for almost any reasonable line length (i.e. the one that makes sense to display on the console at all), it is almost constant.

Bottom line: big-O is the limit as N approaches infinity - but you only have to write relatively small amounts of data to the console (and quite slowly), so big-O is almost never relevant to this task.



All Articles