0

I have a piece of code that says:

for i = 4,16, . . . , n

I am trying to find an upper bound in terms of big oh notation for the number of times the statement gets executed. I believe here it goes like 4,42,43 ... and so on. Since it grows exponentially, it looks like to me that that code is executed about O(logn) times. Am i right? Thanks in advance.

yrazlik
  • 10,411
  • 33
  • 99
  • 165
  • add a counter in your code and increment it, you'll have your answer right away – JMan Feb 26 '13 at 09:10
  • 1
    Without more information, this could also mean `i` is incremented by 12 in each step, which would give O(n). – Henry Feb 26 '13 at 09:34

1 Answers1

2

You can confirm your result by thinking in terms of a loop whose index variable is used as the exponent, taking the values 1, 2, 3, ... , floor(log_4(n))

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75