user10975016
user10975016

Reputation:

What is the time complexity of this code block?

How can I calculate the time complexity?

While(n>0)
      For j in n
          Count+=1
      n = n/2

Upvotes: 1

Views: 321

Answers (1)

Shuki Avraham
Shuki Avraham

Reputation: 1043

O(n).

n+ n/2 + n/4 + ... = 2n = O(n)

Upvotes: 9

Related Questions