What is the time complexity for “Hello, World” function?

Technology CommunityCategory: Big-O NotationWhat is the time complexity for “Hello, World” function?
VietMX Staff asked 3 years ago
Problem

Consider the code:

int main() 
{ 
    printf("Hello World"); 
} 

What is the time complexity of this function?

Someone may provide the simple (and wrong) answer is O(1) as “Hello World” prints only once on a screen (hence just one operation is needed to finish the function).

Right answer:

Big O notation in this context is being used to describe a relationship between the size of the input of a function and the number of operations that need to be performed to compute the result (output) for that input.

That operation has no input that the output can be related to, so using Big O notation is nonsensical. The time that the operation takes is independent of the inputs of the operation (which is…none). Since there is no relationship between the input and the number of operations performed, you can’t use Big O to describe that non-existent relationship. Even worse; this isn’t technically an algorithm. An algorithm is a method for computing the value of a mathematical function — maths functions are a mapping from one input to an output. Since this takes no input and returns nothing, it’s not a function, in the mathematical sense.