What Is The Time Complexity when There Are Four Variables Used Arithmetically in a Program?

Question
You have a program with four variables that are used in arithmetic, but no other operations happen. (There are no while or for loops at all.) What is the time complexity of such an algorithm?

Answer
O(1). An algorithm, as long as the number of operations is fixed or constant, can be considered to have O(1) time complexity. The source is page 39 of Elements of Programming Interviews in Python.

Leave a comment

Your email address will not be published. Required fields are marked *