-2

I am learning to analyze the big O complexity of various problem sets.

Here is the code

I know the Big O of an if-else construct is O(1) but can't seem to figure it out for this one. Will it be O(N), where N is the no. of if statements, or will it be O(1)?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 3
    Why would it be O(n)? if every if statement is O(1), and there is no data structure in size n, so of course it will be O(1) – sheldonzy Dec 03 '17 at 10:14
  • there is nothing like 'O(4)' or 'O(5)'. it's either linear O(1) with any _constant_ multiplier or something(quadratic, cubic, factorial etc) else. See https://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notation – skyboyer Dec 10 '17 at 10:18

1 Answers1

1

Big O notation deals with algorithms as they scale based on the input size. In this example, there is no input n. No matter how large your problem size is, your code will execute in O(1) time.

td_simpson
  • 52
  • 1
  • 4