gpt4 book ai didi

c++ - 每次迭代递增 i*2 并在
转载 作者:行者123 更新时间:2023-11-28 04:59:28 25 4
gpt4 key购买 nike

我知道如果 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循环

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

{}

最佳答案

似乎是 O(log n)。可以这么说,您每次都将集合减半。

关于c++ - 每次迭代递增 i*2 并在 <n 时终止的 for 循环的大 O 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46437322/

25 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com