每次迭代递增 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?
我知道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)。可以说,您每次都将收藏夹切成两半。
相关文章:
- "error: no matching function for call to"构造函数错误
- 表示"accepting anything for this template argument" C++概念的通配符
- 如何在C++中从两个单独的for循环中添加两个数组
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 在Linux for Windows上编译C++代码时出错
- 调用专用模板时出错"no matching function for call to [...]"
- 为什么我的for循环不能正确获取argv
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 在基于范围的for循环中使用结构化绑定声明
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 程序终止,状态为 -1073741510 在 for 循环的中间,将输入分配给二维数组
- 程序似乎在 for 循环 - C++后静默终止
- 每次迭代递增 i*2 并在 <n 时终止的 for 循环的大 O 是多少?
- 错误:"for"之前应为非限定 id。编译由于 -Wfatal 错误而终止
- For 循环结束自身并终止正在运行的程序,但在删除斜率计算语句时正常运行
- 当索引超过其长度时,C++for循环会自动安全地终止char*
- 带有指针和终止 null 的 For 循环
- 连续 for 循环不会终止C++