每次迭代递增 i*2 并在 <n 时终止的 for 循环的大 O 是多少?

what is the big O of a for loop that increments by i*2 each iteration and terminates when <n?

本文关键字:for 终止 循环 多少 迭代 lt 并在      更新时间:2023-10-16

我知道n = 0是否运行0次

n = 1 the loop runs 1 time
n = 2 the loop runs 2 times
n = 3 the loop runs 2 times
n = 4 the loop runs 3 times

等等,但我不知道如何概括。

这是For Loop

  for(int i = 1 ; i< n; i*=2)

{}

似乎是o(log n)。可以说,您每次都将收藏夹切成两半。