【问题标题】:I need help to calculate the complexity of this algorithm我需要帮助来计算这个算法的复杂度
【发布时间】:2021-08-02 04:11:04
【问题描述】:

我不确定我是否得到了正确的复杂性。我找到了 \mathcal{O}(\sqrt{n})。

首先我计算了分配和比较的总和:

分配:1 + 1 + 1 +\sqrt{n} + 1

比较:\sqrt{n} +\sqrt{n} + 1

总和:3\sqrt{n} + 5

复杂度 = \mathcal O(\sqrt{n})

有人可以和我确认答案是否正确吗?

Mystere Algorithm

【问题讨论】:

    标签: algorithm time-complexity big-o discrete-mathematics


    【解决方案1】:

    是的,while-loop 进行sqrt(n) 轮,每轮执行恒定数量的操作,复杂度为O(sqrt(n))

    (顺便说一句,这是获取n的整数除数的算法)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多